Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Children as string with xmlreader and C#
    primarykey
    data
    text
    <p>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.</p> <p>ReadInnerXML and ReadOutterXML break up everything for me</p> <p>example XML:</p> <pre><code>&lt;?xml version="1.0" standalone="yes"?&gt; &lt;main&gt; &lt;parse1&gt; //finding this will get full inner or outter xml - either one - my issue &lt;parse2 /&gt; // even getting the children above might still need parse chldren &lt;negligeable /&gt; // not all children interest me &lt;/parse1&gt; &lt;parse3&gt;some text&lt;/parse3&gt; // not all children of main are the same but all need be parsed &lt;/main&gt; </code></pre> <p>Hope this gives you a general idea of what i need</p> <p>i can parse 2 and 3 right now and ignore what i don't need but if i use ReadInnerXML or ReadOutterXML when i find the tag then it won't let me parse anything else - not even the tag wich is outside .</p> <p>ReadInnerXML and ReadOutterXML do return the text i need correctly but cause everything else to not be parsed</p> <p><strong>EDIT:</strong> as per dasblinkenlight sugestion, some code:</p> <pre><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; } } } </code></pre> <p>Result should be (given the test xml)</p> <pre><code>Contents of Parse 1: &lt;parse2 /&gt;&lt;negligeable /&gt; Parse 2 tag exists Contents of Parse 3: some text </code></pre> <p>Am also trying ReadSubTree</p> <p>Any hints?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload