Note that there are some explanatory texts on larger screens.

plurals
  1. POObject reference problem when reaching the end of a XML string
    text
    copied!<p>I've been developing a small xml parser for a specific file with this data structure :</p> <pre><code>&lt;questionnaire type="Echo"&gt; &lt;quest etat="0" ord="0"&gt; &lt;intro&gt; &lt;t&gt;bla bla bla&lt;/t&gt; &lt;/intro&gt; &lt;rep1&gt; &lt;t&gt;word&lt;/t&gt; &lt;ev id="Q0R1"/&gt; &lt;/rep1&gt; &lt;rep2&gt; &lt;t&gt;word&lt;/t&gt; &lt;ev id="Q0R2"/&gt; &lt;/rep2&gt; &lt;/quest&gt; &lt;/questionnaire&gt; </code></pre> <p>The <code>&lt;quest&gt;&lt;/quest&gt;</code> tag is repeated 70 times in fact.</p> <p>Here is the parser I developed in C# and which takes the parameter "xmlString" containing the XML to parse :</p> <pre><code>XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(xmlString)); while(reader.ReadToFollowing("quest")) { Console.WriteLine("================================="); Console.WriteLine("ID : " + reader.GetAttribute("ord").ToString()); reader.ReadToFollowing("intro"); reader.ReadToFollowing("t"); Console.WriteLine("TEXTE : " + reader.ReadString()); reader.ReadToFollowing("rep1"); reader.ReadToFollowing("t"); Console.WriteLine("REPONSE1 : " + reader.ReadString()); reader.ReadToFollowing("ev"); Console.WriteLine("CLE1 : " + reader.GetAttribute("id").ToString()); reader.ReadToFollowing("rep2"); reader.ReadToFollowing("t"); Console.WriteLine("REPONSE2 : " + reader.ReadString()); reader.ReadToFollowing("ev"); Console.WriteLine("CLE2 : " + reader.GetAttribute("id").ToString()); Console.WriteLine("ETAT : False"); } </code></pre> <p>Everything is ok through the 69 first &lt; quest >, but when reaching the 70th, it the fields TEXTE and REPONSE1 are empty and it goes through a NullReferenceException at the line :</p> <pre><code>Console.WriteLine("CLE1 : " + reader.GetAttribute("id").ToString()); </code></pre> <p>Can anybody tell me what's wrong ?? Thanks in advance.</p>
 

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