Insert element into XML with compliance to a schema

L

Leura

I have a new XML document parsed in as DOM. Then I have an element to insert
according to the order spesified in a schema.

For example:

I have a XML:

<book>
<chapter1>Introduction</chaper1>
<chapter4>Chapter4</chapter4>
<chapter5>Chapter5</chapter5>
</book>

I need to insert "<book><chapter2>Chapter2></chapter2></book>". Accoding to
schema, the <chapter2> must be after <chapter1> and before <chapter3> that
is missing in this case.

(if I know the element to be insert at a certain position, in this case the
second, it's easy to do. However, generally the position is not known, only
an order determined by the schema.)

How can I generally solve this problem? Is there any way to read in the
schema and perform the insertion according to it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top