0

I am sending, on the server side, a xml to a remote server, the remote server will respond back with a xml response.

I am assuming it is a stream.

How can I receive the stream, and parse the values into a dictionary or hashtable?

note, the response will be like this:

<root>
<name1>blah</name1>
<name2>blahasdf</name2>
...
</root>
mrblah
  • 99,669
  • 140
  • 310
  • 420

3 Answers3

1

How does one parse XML files? ?

Community
  • 1
  • 1
Dmitry
  • 3,740
  • 15
  • 17
0

You can use either Linq2XML, or XPath. If the XML is generated by a SOAP Webservice, you can Visual Studio generate the code, using 'Add Service Reference'.

example in LINQ 2 XML:

        var x = XDocument.Load("XmlFile1.xml");

        var elems = (from elem in x.Element("root").Elements()
                    select elem.Value).ToList();
Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120
  • I am not sure how you'd use XSLT in this case - it is mostly useful for transforming one type of XML document into another XML format. – Anton Nov 23 '09 at 22:49
0

If you're on .NET 3.5 you can do this:

string xml =
  @"<root>
        <name1>blah</name1>
        <name2>blahasdf</name2>
    </root>"

Dictionary<string, string> dict =
    XElement.Parse(xml)
            .Elements()
            .ToDictionary(x => x.Name.LocalName, x => x.Value);
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452