Differences between ReadValue, ReadString, ReadContentAsString, and ReadElementContentAsString by: vkvi Source: Qianyi Network (original) Time:
- ReadOuterXml and ReadInnerXml
- Differences between Value, ReadString, ReadContentAsString, and ReadElementContentAsString
There are many methods and attributes for reading values in XmlReader. Here we take reading strings as an example to introduce their differences.
|
From the upper-level node |
Slave Node |
Slave text node |
"Pointer" movement |
Value |
Cannot be obtained |
Cannot be obtained |
Successful |
Do not move |
ReadString () |
Error |
Successful |
Successful |
End Node of the current node |
ReadContentAsString () |
Error |
Error |
Successful |
End Node of the current node |
ReadElementContentAsString () |
Error |
Successful |
Error |
Next sibling node of the current node |
- From upper-level node: read from the upper-level node of Text or CDATA
- Read from the upper-level node: read from the upper-level node of Text or CDATA
- From Text node: read from Text or CDATA
- "Pointer" movement: when reading is completed and moving to the next node
Example
XML snippets:
<N1> <n1.1> content1 </n1.1> <n1.2> content2 </n1.2> </n1>
If the current pointer is n1:
- Zero-length Value string
- ReadString () Error
- ReadContentAsString () Error
- ReadElementContentAsString () Error
If the current pointer is n1.1:
- Zero-length Value string
- ReadString () content1
- ReadContentAsString () Error
- ReadElementContentAsString () content1
If the current pointer is content1:
- Value content1
- ReadString () content1
- ReadContentAsString () content1
- ReadElementContentAsString () Error
"Pointer" movement:
- Value unchanged
- ReadString () </n1.1>
- ReadContentAsString () </n1.1>
- ReadElementContentAsString () <n1.2>