I am parsing an xml string using xmlreader in c#, but as i parse i need sometimes to get the full content of a node including children with tags and still be able to continue parsing.
ReadInnerXML和ReteOutterXML打破了我所有的大门。
example XML:
<?xml version="1.0" standalone="yes"?>
<main>
<parse1> //finding this will get full inner or outter xml - either one - my issue
<parse2 /> // even getting the children above might still need parse chldren
<negligeable /> // not all children interest me
</parse1>
<parse3>some text</parse3> // not all children of main are the same but all need be parsed
</main>
希望使大家对需要做什么有一个普遍的想法。
i 现在可以把2和3同起来,忽视不需要什么,但如果在发现标签时使用“读式”或“读式”法,那么就让我放弃任何其他东西——甚至连帽子都不在。
ReadInnerXML and ReadOutterXML do return the text i need correctly but cause everything else to not be parsed
<>strong>EDIT: as per dasblinkenlight sugestion, some Code:
using (XmlReader reader = XmlReader.Create(new StringReader(XmlString)))
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.Name)
{
case "parse1":
Console.WriteLine("Contents of Parse 1: {0}", ?function here?);
break;
case "parse2":
Console.WriteLine("Parse 2 tag exists");
break;
case "parse3":
Console.WriteLine("Contents of Parse 3: {0}", Reader.ReadElementContentAsString());
break;
}
break;
}
}
}
成果应当是(经过测试xml)
Contents of Parse 1: <parse2 /><negligeable />
Parse 2 tag exists
Contents of Parse 3: some text
Am 并试图阅读
任何方面?