Differences between readvalue, readstring, readcontentasstring, and readelementcontentasstring

Source: Internet
Author: User
Tags cdata
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>

    Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.