Note that there are some explanatory texts on larger screens.

plurals
  1. POxmlTextReader.ReadInnerXml() is pulling in my entire XML doc into one variable
    text
    copied!<p>I am creating XML index files to be read in a later step. I have variable length arrays, and I am writing them to one file.</p> <p>There is a problem, I think its inside the reader code. For some reason the TimeStamp and Long elements are read into arrays properly, but the Lat and VideoFile elements are skipped. For some reason, thier reader.nodetype is never returned. The only way the read() method picks them up is in a TEXT nodetype, and then it only shows the innerxml value, which is useless to me.</p> <p>The code below should be fully runnable once you save an example of the XML file.</p> <p>Once again, thank-you stack users.</p> <h2>Creation</h2> <pre><code> using System.Xml; XmlTextWriter xmlwriter = new XmlTextWriter(file, null); xmlwriter.Formatting = Formatting.Indented; //xmlwriter.Indentation = 4; xmlwriter.WriteStartDocument(); xmlwriter.WriteStartElement("Index"); for (int i = 0; i &lt; malLat.Count; i++) { xmlwriter.WriteStartElement("Marker"); xmlwriter.WriteStartElement("TimeStamp"); xmlwriter.WriteString(malTimes[i].ToString()); xmlwriter.WriteEndElement(); xmlwriter.WriteStartElement("Lat"); xmlwriter.WriteString(malLat[i].ToString()); xmlwriter.WriteEndElement(); xmlwriter.WriteStartElement("Long"); xmlwriter.WriteString(malLong[i].ToString()); xmlwriter.WriteEndElement(); xmlwriter.WriteStartElement("VideoFile"); xmlwriter.WriteString(malVideoTitle[i].ToString()); xmlwriter.WriteEndElement(); xmlwriter.WriteEndElement(); } xmlwriter.WriteEndElement(); xmlwriter.WriteEndDocument(); xmlwriter.Close(); </code></pre> <h2>Reading</h2> <pre><code>using System.Xml; XmlTextReader lxmlReader = new XmlTextReader(mstrIndexFile + ".xml"); lxmlReader.WhitespaceHandling = WhitespaceHandling.None; while (lxmlReader.Read()) { if (lxmlReader.NodeType == XmlNodeType.Element) { if (lxmlReader.Name == "TimeStamp") { malTimes.Add(lxmlReader.ReadInnerXml().ToString()); } else if (lxmlReader.Name == "Lat") { malLat.Add(lxmlReader.ReadInnerXml().ToString()); } else if (lxmlReader.Name == "Long") { malLong.Add(lxmlReader.ReadInnerXml().ToString()); } else if (lxmlReader.Name == "VideoFile") { malVideoTitle.Add(lxmlReader.ReadInnerXml().ToString()); } } } lxmlReader.Close(); </code></pre> <h2>XML Doc Sample</h2> <pre><code> &lt;Index&gt; &lt;Marker&gt; &lt;TimeStamp&gt;2011-7-17 23:18:39&lt;/TimeStamp&gt; &lt;Lat&gt;-121.261953323166&lt;/Lat&gt; &lt;Long&gt;43.0594755392741&lt;/Long&gt; &lt;VideoFile&gt;C:\Users\kpenner\Desktop\Video Dev\1_1.wmv&lt;/VideoFile&gt; &lt;/Marker&gt; &lt;Marker&gt; &lt;TimeStamp&gt;2011-7-17 23:18:40&lt;/TimeStamp&gt; &lt;Lat&gt;-122.260755&lt;/Lat&gt; &lt;Long&gt;46.05878&lt;/Long&gt; &lt;VideoFile&gt;C:\Users\kpenner\Desktop\Video Dev\1_1.wmv&lt;/VideoFile&gt; &lt;/Marker&gt; &lt;/Index&gt; </code></pre>
 

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