tags:

views:

102

answers:

3

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>
A: 

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
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.
antonm
Meant XPath, it's late :-)
Jan Jongboom
A: 

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