Hey guys.
I want to move over a xml data using the XmlReader. The problem is
that the XmlReader.Create function demands (at least in .net 2.0) a
file location, while I need to provide a string of xml data instead
I know I can use the XmlDocument class, but it has to be a simpler
way.
Thanks in advance.
Henk Verhoeven - 27 Aug 2007 21:00 GMT
Hi Victor
When you use the XMLTextReader then you have an overload using a String
Reader type which is a basic string.
From the MSDN example
http://msdn2.microsoft.com/en-us/library/0ax3f4f3.aspx
string xmlData =
@"<book>
<title>Oberon's Legacy</title>
<price>5.95</price>
</book>";
// Create the reader.
XmlTextReader reader = new XmlTextReader(new StringReader(xmlData));
reader.WhitespaceHandling = WhitespaceHandling.None;
// Display each element node.
while (reader.Read()){
switch (reader.NodeType){
case XmlNodeType.Element:
Console.Write("<{0}>", reader.Name);
break;
case XmlNodeType.Text:
Console.Write(reader.Value);
break;
case XmlNodeType.EndElement:
Console.Write("</{0}>", reader.Name);
break;
}
}
// Close the reader.
reader.Close();
Henk
> Hey guys.
> I want to move over a xml data using the XmlReader. The problem is
[quoted text clipped - 4 lines]
>
> Thanks in advance.
Victor Rosenberg - 28 Aug 2007 05:34 GMT
Thanks!
> Hi Victor
>
[quoted text clipped - 43 lines]
>
> > Thanks in advance.
Martin Honnen - 28 Aug 2007 14:16 GMT
> I want to move over a xml data using the XmlReader. The problem is
> that the XmlReader.Create function demands (at least in .net 2.0) a
> file location, while I need to provide a string of xml data instead
> I know I can use the XmlDocument class, but it has to be a simpler
> way.
XmlReader.Create(new StringReader(yourStringVariable))
should do.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/