0

Here is the xml file that I need to process as part of my assignment.

<?xml-stylesheet type="text/xsl" href="people.xsl"?>
<People>
    <Person>
    `...`
    </Person>

    `...` 
</People>

I am using the "javax.xml.parsers.DocumentBuilderFactory" to create a dom parser. After parsing, the resultant document does not have People at the root but some root having children as xml-stylesheet and People.

Looks like this can be avoided.

1
  • there is no question here, what do you want to do? Also if this is homework, please tag it as such. Commented Nov 13, 2009 at 6:58

1 Answer 1

1

<?xml-stylesheet ... ?> is not an XML declaration. It is a Processing Instruction (PI), and the DOM spec says that a Document node may contain zero or more of them.

One approach would be to code your application to deal appropriately with (e.g. ignore) an PI's in the Document node. Alternatively, just use the Document node's documentElement attribute / getter to get the root Element directly.

Sign up to request clarification or add additional context in comments.

1 Comment

To clarify: nothing has been 'converted'. an XML DOM Document node can have multiple children. One of them is the root element. The rest are processing instructions or comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.