juli jul wrote:
How can I get a xml node from a XmlTextReader?
The XmlTextReader itself has no method for that but you can pass the
reader to the method ReadNode of an XmlDocument object which then
creates the node.
Here is a simple example that uses the reader to read through an XML
document, looking for an element node with node name 'god' and then
creates an XmlElement of that:
XmlTextReader xmlReader = new XmlTextReader(args[0]);
XmlDocument xmlDocument = new XmlDocument();
XmlElement god = null;
while (xmlReader.Read()) {
if (xmlReader.NodeType == XmlNodeType.Element &&
xmlReader.Name == "god")
{
god = (XmlElement) xmlDocument.ReadNode(xmlReader);
break;
}
}
xmlReader.Close();
if (god != null) {
Console.WriteLine("Found {0} with OuterXml:\r\n{1}", god,
god.OuterXml);
}
}
Here is the documentation of ReadNode:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlDocumentClassReadNodeTopic.asp>
--
Martin Honnen
http://JavaScript.FAQTs.com/