[Mono-list] Bug in property System.Xml.XmlTextReader.Depth

Francesco FD. Delfino fdelfino@napoli.consorzio-cini.it
Sun, 4 Aug 2002 12:45:26 +0200


Hi,
Just found another bug, which actually prevents using lower level xmltextreader api. 
The bogus property is
  System.Xml.XmlTextReader.Depth
I just hacked the code of this property to print out the "real" value 
(the property actually return 0 if the underlying attribute value 'depth' is less then zero)
It seems that when a closing tag is parsed, the depth variable is decremented 3 times (instead of once).
At the end of the email, you will find the c# code and the .xml file used as test.
Regards,
   Francesco
--- MS.NET OUTPUT ---
0 - <stream:stream to='tipic.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>
1 - <presence/>
1 - <presence>
</presence>
1 - <presence>
</presence>
1 - <presence from='xxx@tipic.com/TipicIM' to='yyy@tipic.com'>
</presence>
1 - <presence from='xxx@tipic.com/TipicIM' to='yyy@tipic.com'>
</presence>
1 - <presence from='xxx@tipic.com/TipicIM' to='yyy@tipic.com'>
</presence>
</stream:stream>
--- END MS.NET OUTPUT ---
--- MINT OUTPUT ---
RealDepth 0
0 - <stream:stream to='tipic.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>
RealDepth 1
1 - <presence/>
RealDepth 1
1 - <presence>
</presence>
RealDepth -2
0 - <presence>
</presence>
RealDepth -5
0 - <presence from='xxx@tipic.com/TipicIM' to='yyy@tipic.com'>
</presence>
RealDepth -8
0 - <presence from='xxx@tipic.com/TipicIM' to='yyy@tipic.com'>
</presence>
RealDepth -11
0 - <presence from='xxx@tipic.com/TipicIM' to='yyy@tipic.com'>
</presence>
</stream:stream>
--- END MINT OUTPUT ---
--- CUT HERE: c# function ---
public static void Parse() 
{  
 System.Xml.XmlReader textReader = new System.Xml.XmlTextReader("c:\\test.xml");
 while (textReader.Read()) 
 {
  switch (textReader.NodeType) 
  {
   case XmlNodeType.Element:
    Console.Write("<{0}", textReader.Name);
    bool isempty = textReader.IsEmptyElement;
       // set the element's attributes.
       while (textReader.MoveToNextAttribute ()) 
        Console.Write(" {0}='{1}'",textReader.Name, textReader.Value);
    if (isempty) 
     Console.WriteLine("/>");
    else
     Console.WriteLine(">");       
       textReader.MoveToElement ();
    break;
   case XmlNodeType.Text:
    Console.Write(textReader.Value);
    break;
   case XmlNodeType.CDATA:
    Console.Write("<![CDATA[{0}]]>", textReader.Value);
    break;
   case XmlNodeType.ProcessingInstruction:
    Console.Write("<?{0} {1}?>", textReader.Name, textReader.Value);
    break;
   case XmlNodeType.Comment:
    Console.Write("<!--{0}-->", textReader.Value);
    break;
   case XmlNodeType.XmlDeclaration:
    Console.Write("<?xml version='1.0'?>");
    break;
   case XmlNodeType.Document:
    break;
   case XmlNodeType.DocumentType:
    Console.Write("<!DOCTYPE {0} [{1}]", textReader.Name, textReader.Value);
    break;
   case XmlNodeType.EntityReference:
    Console.Write(textReader.Name);
    break;
   case XmlNodeType.EndElement:
    Console.WriteLine("</{0}>", textReader.Name);
    break;
  }       
 }      
}
--- END: c# function ---
--- CUT HERE: save as c:\test.xml ---
<stream:stream to='tipic.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>
<presence/>
<presence></presence>
<presence></presence>
<presence from="xxx@tipic.com/TipicIM" to="yyy@tipic.com"></presence <mailto:yyy@tipic.com"> >
<presence from="xxx@tipic.com/TipicIM" to="yyy@tipic.com"></presence <mailto:yyy@tipic.com"> >
<presence from="xxx@tipic.com/TipicIM" to="yyy@tipic.com"></presence <mailto:yyy@tipic.com"> >
</stream:stream>
--- END: test.xml ---