tags:

views:

197

answers:

2

My question is this:

If I have the following XML:

<root>
  <alpha one="start">
    <in>1</in>
  </alpha>
</root>

and then I'll add the following path:

<root><alpha one="start"><out>2</out></alpha></root>

which results in

<root>
  <alpha one="start">
    <in>1</in>
  </alpha>
</root>
<root>
  <alpha one="start">
    <out>2</out>
  </alpha>
</root>

I want to be able to convert it into this:

<root>
  <alpha one="start">
    <in>1</in>
    <out>2</out>
  </alpha>
</root>

Besides implementing it myself (don't feel like reinventing the wheel today), is there a specific way in Xerces (2.8,C++) to do it?

If so, at which point of the DOMDocuments life is the node merging done? at each insertion? at the writing of the document, explicitly on demand?

Thanks.

A: 

Isn't it just a one minute task if you know the names of the container tag where various different tags are present?

In your example, get a pointer to the alpha tag in all the XML documents and put the contents of all of them into a new document's alpha if they're not present there already.

This isn't as bad as reinventing the wheel. I'm not familiar with Xerces, but with libxml++, I would call this an easy task.

Sahasranaman MS
+1  A: 

If you use xalan its possible to use an xpath to find the element and directly insert into the correc one.

The following code may be slow but returns all "root" elments with the attribute "one" set to "start".

selectNodes("//root[@one="start"]")

It is probably better to use the full path

selectNodes("/abc/def/.../root[@one="start"]")

or if you already have the parent element work relative

selectNodes("./root[@one="start"]")

I think to get the basic concepts xpath on wikipedia.

Totonga