Reding XML

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

(thanks to an earlier post) I've written some XML to a string using
XmlTextWriter and StringWriter. Which all works and creates XML like

<title000>abc</title000>
<url000>efg</url000>
<title001>abc</title001>
<url001>efg</url001>

Can someone please show me how I read this back using XmlTextReader -
specifically I want to be able to say "get me the contents of tag <title001>
and also tell me if this tag does not exist.

I just can't get any code to work
TIA
 
Yes - The following is what I want - but how do I pass a string containing
XML rather than point at an xml file?

here is the code
use Dom Parsing

XmlDocument objDoc=new XmlDocument();
objDoc.Load("a.Xml");
XmlNode objNode;
objNode= objDoc.SelectSingleNode("//QueryResult/HERE");
MessageBox .Show(objNode.InnerXml );

XmlNode objSecNode;
objSecNode= objNode.SelectSingleNode("ExternalIntegrator/Entities");
MessageBox .Show(objSecNode.InnerXml );

MessageBox.Show(objSecNode.ChildNodes[0].InnerText);
MessageBox.Show(objSecNode.ChildNodes[1].InnerText);
MessageBox.Show(objSecNode.ChildNodes[2].InnerText);

objDoc=null;
 
hi

replace the second line of code by the following

objDoc.LoadXml( myXmlString);

regards
Ansil

Tony said:
Yes - The following is what I want - but how do I pass a string containing
XML rather than point at an xml file?

here is the code
use Dom Parsing

XmlDocument objDoc=new XmlDocument();
objDoc.Load("a.Xml");
XmlNode objNode;
objNode= objDoc.SelectSingleNode("//QueryResult/HERE");
MessageBox .Show(objNode.InnerXml );

XmlNode objSecNode;
objSecNode= objNode.SelectSingleNode("ExternalIntegrator/Entities");
MessageBox .Show(objSecNode.InnerXml );

MessageBox.Show(objSecNode.ChildNodes[0].InnerText);
MessageBox.Show(objSecNode.ChildNodes[1].InnerText);
MessageBox.Show(objSecNode.ChildNodes[2].InnerText);

objDoc=null;



Ansil MCAD said:
hi
are you strict you want to use XmlText reader,i would prefer you go for a
dom parser

please check a similar posting to read from an xml document

regards
Ansil

http://www.msdn.microsoft.com/newsg...6b4fcb-e863-4926-a705-a2a2562377b3&sloc=en-us
 
Back
Top