Rocket U2 | UniVerse & UniData

 View Only

 [Universe/XDOM api] How to insert an xml fragment from string into an existing DomHandle ?

Corentin Leblanc's profile image
Corentin Leblanc posted 06-22-2022 11:47

Hello,

Im using XDOM api in Universe 11.3.1 and I'm trying to import 'an xml fragment' from string into a current nodeHandle.

Explanations :

1 - Im creating an handle with XDOMOpen 
2 - Im appending a node into this handle
Example, at this time, my handle is a tree like this :
<root>
  <child>
  </child>
</root>

3 - Im using XDOMLocate to get a new handle to "child" node, nammed childNodeHandle.
4 - Now, I want to append to childNodeHandle an 'xml fragment' from a string (for example '<subChild><subSubChild><subSubSubChild></subSubSubChild></subSubChild></subChild>')

Problem : if I do a new XDOMOpen with this fragment and get a fragmentHandle, I cant use XDOMIAppend/XDOMInsert(childNodeHandle....fragmentHandle) because childNodeHandle and fragmentHandle are not in the same tree in memory - its normal (I got this error  : DOM Exception code: 4 (A node is used in a different document than the one that created it (that doesn't support it))

I cant use XDOMCreateNode either because XDOMCreateNode only allow to add ONE node, not a fragment.

=> I havent found a solution to insert this xml fragment into childNodeHandle without browsing recursively all nodes from fragmentHandle (and it is really really wordy...)

I think XDOM api is using java api like org.w3c.dom, or axis, xerces, who provides 'importNode' function but there is no implementation like XDOMImport.

Have you an idea for achieving this goal without browsing all nodes from fragment handle ?

Thanks for your help,
Corentin