Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading xml-strings 1

Status
Not open for further replies.

Salte2

Programmer
Nov 5, 2004
17
0
0
NO
I am dealing with a web-service that returns string-objects in xml-format. A bit simplified they look like this: "<error><code>514</code><description>User not found</description></error>". Are there any classes / methods in .net i can use that will translate this xml-code for me so i can just get the error-code or description without having to search through the string myself? I find a lot of Xml-reader stuff in the msdn, but they seem to be dealing with files and streams, not strings.
 
Have a look at the XmlDocument class! It lets you load string

XmlDocument myDocument = new XmlDocument();
string bla ="error><code>514</code><description>User not found</description></error>";
myDocument.LoadXml(bla);

And it also lets you select the nodes you want to use!

myDocument.SelectSingleNode("//description");

This would return User not found! You can enter any Xpath Query you like into the SelectSingleNode operation!

Hope that gets you started!

Stephan
 
Thank you very much, that was exactly what i needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top