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