XML processing question

R

Rahul

Hi,

I want to do the following

<A>
<B attr1="1" attr2="2">
.................
</B>
<B attr1="4" attr2="5">
.................
</B>

......................
<B attr1="1" attr2="2">
<repeat attr1="1" attr2="2> // Here I want to insert the
first <B> element which had attr=1 and attr=2
</B>
</A>

The problem is to replace the <repeat> element with the sibling of its
parent (repeat will always be done for the sibling of parent of
repeat) which has the given attribute values.

Can I do this in DOM, or I need to pre process the XML using XSD.

Thanks in advance
Rahul
 
P

Pavel Lepin

Rahul said:
<A>
<B attr1="1" attr2="2">
.................
</B>
<B attr1="4" attr2="5">
.................
</B>

......................
<B attr1="1" attr2="2">
<repeat attr1="1" attr2="2> // Here I want
to insert the
first <B> element which had attr=1 and attr=2
</B>
</A>

The problem is to replace the <repeat> element with the
sibling of its parent (repeat will always be done for the
sibling of parent of repeat) which has the given attribute
values.

Can I do this in DOM, or I need to pre process the XML
using XSD.

I fail to see how a schema definition would help you with
this, unless you're using some sort of sophisticated
schema-based data-binding library.

Your problem can certainly be solved by iterating over the
DOM, but if your API allows you to evaluate XPath
expressions (which is quite likely) this would be even
easier. Transforming your document using XSLT before
stuffing it into your application is a viable option too.

Which one of these options would be better in your case is
impossible to tell without knowing a lot more about your
platform, your documents and the actual problem you're
facing.
 

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
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top