Odczytanie pliku

0

hej mam taki plik XML:

<gxl xmlns:xlink=" http://www.w3.org/1999/xlink">
  <graph id="simpleExample-instance" edgeids=" true" edgemode=" directed" hypergraph=" false">
    <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#simpleExampleSchema" xlink:type=" simple"/>
    <node id="p">
      <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Proc" xlink:type=" simple"/>
      <attr name=" file">
        <string> main.c</string>
      </attr>
    </node>
    <node id="q">
      <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Proc" xlink:type=" simple"/>
      <attr name=" file">
        <string> test.c</string>
      </attr>
    </node>
    <node id="v">
      <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Var" xlink:type=" simple"/>
      <attr name=" line">
        <int> 225</int>
      </attr>
    </node>
    <node id="w">
      <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Var" xlink:type=" simple"/>
      <attr name=" line">
        <int> 316</int>
      </attr>
    </node>
    <edge id="r1" to="v" from="p">
      <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Ref" xlink:type=" simple"/>
      <attr name=" line">
        <int> 127</int>
      </attr>
    </edge>
    <edge id="r2" to="w" from="q">
      <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Ref" xlink:type=" simple"/>
      <attr name=" line">
        <int> 27</int>
      </attr>
    </edge>
    <edge id="c" to="q" from="p">
      <type xlink:href="http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Call" xlink:type=" simple"/>
      <attr name=" line">
        <int> 42</int>
      </attr>
    </edge>
  </graph>
</gxl>

Za pomoca jakich klas moge odcztac ten dokument. Istotne jest pozyskanie

to="q" from="p"

z krawedzi dzieki za pomoc

0
xmlreader napisał(a)

Za pomoca jakich klas moge odcztac ten dokument.

Zobacz tutaj.

0

masz sporo wystarczylo sie pofaygowac i zapytac w google, albo przynajmniej w dziale newbie.
Przykladowe klasy:
System.Xml.XmlTextReader, System.Xml.XPath.XPathDocument, System.Xml.Linq.XDocument

Edit: Mendoza byl szybszy, ale z racji tego ze dis niedziela a za oknem pada i nie mam co robic to dam Ci przyklad z linq ;]:


XDocument doc2 = XDocument.Load(twojplik);
            var query2 = (from f in twojplik.Descendants("edge")
                         where f.Attribute("to").Value == "q" && f.Attribute("from").Value == "p"
                         select f).SingleOrDefault();
0

no niestety coś mi nie pykło:
Mam ciągle błąd :
"Nieoczekiwana deklaracja DTD"

private void CreateReader()
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            settings.ProhibitDtd = false;
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            try
            {
                XmlReader reader = XmlReader.Create(FilePath, settings);
                Lol(reader);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        private void Lol(XmlReader reader)
        {
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        while (reader.MoveToNextAttribute())
                        {
                            label1.Text += reader.Name + " " + reader.Value + "\n";
                        }
                        break;

                }
            }
        }

dzieki za pomoc

1 użytkowników online, w tym zalogowanych: 0, gości: 1