For XML:
<? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<Pkboy kind = "Site">
<Command name = "price" Object = "game" Password = "ASDFASDF">
<Game name = "World of Warcraft">
<Server name = "Warcraft Server 1">
<Item name = "gold coin" kind = "gold" quantity = "12" gross = "0.5005" maxdollar = "99" mindollar = "88" rate = "6.88"/>
</Server>
</Game>
</Command>
</Pkboy>
Read using xmltextreader:
Byte [] buffer = encoding. utf8.getbytes (XML );
Using (Stream = new memorystream (buffer ))
{
Using (xmltextreader STR = new xmltextreader (Stream ))
{
Str. Read ();
Str. Read ();
Str. Read ();
Assert. areequal ("pkboy", str. Name );
Str. Read ();
Str. Read ();
Assert. areequal ("command", str. Name );
Str. Read ();
Str. Read ();
Assert. areequal ("game", str. Name );
Str. movetofirstattribute ();
Assert. areequal ("World of Warcraft", str. value );
Str. Read ();
Str. Read ();
Str. movetofirstattribute ();
Assert. areequal ("Warcraft Server 1", str. value );
}
}
The above test is normal, that is, after three read () times, it will arrive at the pkboy node. Why?
After tracking, after the first read (),
<? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?>, The name of the display node is XML, that is, the content in <> is treated
One node. Version and so on are all attributes. To obtain these attributes, you must use a group of methods similar to movetofirstattribute. Here, read () Again (),
Then, the document "\ r \ n" is displayed, that is, the second read () contains "\ r \ n". If there is a carriage return, it will be read () once as a node.
If "\ r \ n" is not included, you can directly reach the next node.
Therefore, because the carriage return contains a line break, the first element pkboy will be reached after three times.