Solved a problem of xmltextreader usage, endelement
Source: Internet
Author: User
As follows, none of the examples found on codeguru or codeproject process such a situation:
<A name = "test"/> is the case where no </a> label exists. In this case, processing element a will not encounter endelement.
Here we make a process to determine its depth. Xmltextreader reader = NULL;
Try
{
Reader = new xmltextreader (streamreader );
Startdocument (); // start Analysis
Int dept =-1;
While (reader. Read ())
{
Switch (reader. nodetype)
{
Case xmlnodetype. element:
Hashtable attributes = new hashtable ();
String struri = reader. namespaceuri;
String strname = reader. Name;
If (reader. hasattributes)
{
For (INT I = 0; I <reader. attributecount; I ++)
{
Reader. movetoattribute (I );
Attributes. Add (reader. Name, reader. value );
}
}
Startelement (struri, strname, strname, attributes );
If (Dept! =-1 & reader. depth <= Dept) // process "/>" tags
Endelement (string. Empty, reader. Name, String. Empty );
Dept = reader. depth;
Break;
Case xmlnodetype. endelement:
Endelement (string. Empty, reader. Name, String. Empty );
Break;
Case xmlnodetype. Text:
Characters (reader. value );
Break;
Default:
Break;
}
}
Return (namespace) objectstack. Pop ();
}
Catch (xmlexception E)
{
Console. writeline ("error occured:" + E. Message );
}
Finally
{
If (reader! = NULL) reader. Close ();
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service