Questions about parsing the Java DOM

Source: Internet
Author: User
Tags ming

The following XML code:

<Persons>    < Person>        <name>Jack bauer</name>        <Sex>Male</Sex>        < Age>20</ Age>    </ Person>    < Person>        <name>Xiao ming</name>        <Sex>Male</Sex>        < Age>21st</ Age>    </ Person></Persons>

The child elements of the element parsed with the DOM will contain spaces. What do you mean? Take the root element documentelement, the documentelement in this XML is persons. Then we see that the persons contains two person child elements, but when you output documentelement length, you will be amazed to find out the output 5. This is because the space is included in the parsing. See the following code specifically

<Persons>-----------------------------------------------------------------------< Person>        <name>Jack bauer</name>        <Sex>Male</Sex>        < Age>20</ Age>    </ Person>--------------------------------------------------------------------< Person>        <name>Xiao ming</name>        <Sex>Male</Sex>        < Age>21st</ Age>    </ Person>-----------------------------------------------------------------</Persons>

Use dashed lines instead of spaces. There are three dashed lines above. will be parsed into the element's child elements. That's why the output is 5.

Questions about parsing the Java Dom

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.