title: XDOM API in UniVerse
body: <p>I am building an xml parser and constructor using the XDOM functions in UniVerse 10.1.0. Things are going fine until I get to use the XDOMAddChild function. I can add single elements fine using the handles but I get an error when adding a tree. The manuals indicate adding a tree is fine.</p>
  
  <p>XDOMAddChild function</p>
  
  <p>Syntax</p>
  
  <p>XDOMAddChild(xmlHandle, xpathString, nsMap, nodeHandle, dupFlag)</p>
  
  <p>Description</p>
  
  <p>The XDOMAddChild function finds the xpathString in the context xmlHandle in the 
  DOM structure and inserts a node nodeHandle as the last child of the found node. If 
  the inserted node type is XDOM.ATTR.NODE, this node is inserted as an attribute.</p>
  
  <p>Parameters</p>
  
  <p>The following table describes each parameter of the syntax.
  Parameter Description</p>
  
  <p>xmlHandle The handle to the context. [IN]
  xpathString Relative or absolute Xpath string. [IN]
  nsMap The map of namespaces which resolve the prefixes in the xpath string. 
  Format is “xmlns=default_url xmlns:prefix1=prefix1_url 
  xmlns:prefix2=prefix2_url”</p>
  
  <p>For example:
  “xmlns=<a href="http://myproject.mycompany.com" rel="nofollow noreferrer">http://myproject.mycompany.com</a> 
  xmlns:a_prefix=a.mycompany.com” [IN]</p>
  
  <p>nodeHandle Handle to a DOM subtree. If nodeHandle points to a DOM document, 
  all of its children are inserted, in the same order. [IN]</p>
  
  <p>dupFlag XDOM.DUP: Clones nodeHandle, and inserts the duplicate node.
  XDOM.NODUP: Inserts the original node. The subtree is also removed 
  from its original location. [IN]</p>
  
  <p>I accept the XDOM faults and flaws (particularly with building namespace prefixes) and an willing to work with them, But this one may be a show stopper with the current logic I am using. This is some test code:</p>
  
  <pre><code>$INCLUDE UNIVERSE.INCLUDE XML.H                                           
  DATA.REQ = '&lt;logonResponse&gt;&lt;/logonResponse&gt;'
  TEST.CHILD = '&lt;logon&gt;HELP&lt;/logon&gt;'
  NSMAP = ''
  *
  ERR$ = XDOMOpen(DATA.REQ, XML.FROM.STRING, DOM$H)                
    Status = XMLGetError(ERR$,errMsg)
    PRINT ERR$:',':errMsg 
  ERR$ = XDOMOpen(TEST.CHILD, XML.FROM.STRING, CHILD$H)                
    Status = XMLGetError(ERR$,errMsg)
    PRINT ERR$:',':errMsg
  ERR$ = XDOMLocate(DOM$H,'//logonResponse',NSMAP,NOD$H)                                   
    Status = XMLGetError(ERR$,errMsg)
    PRINT ERR$:',':errMsg
  ERR$ = XDOMWrite(NOD$H,JUNK,XML.TO.STRING)
  PRINT JUNK
  ERR$ = XDOMWrite(CHILD$H,JUNK,XML.TO.STRING)
  PRINT JUNK
  ERR$ = XDOMAddChild(DOM$H, '',NSMAP,CHILD$H, XDOM.NODUP)
  IF ERR$ = XML.SUCCESS THEN PRINT 'SUCCESS'
  IF ERR$ = XML.ERROR THEN PRINT 'ERROR'
  IF ERR$ = XML.INVALID.HANDLE THEN PRINT 'INVALID'
    Status = XMLGetError(ERR$,errMsg)
    PRINT ERR$:',':errMsg
  END
  </code></pre>
  
  <p>I get this back....</p>
  
  <p>1004,A DOM exception occured in function XDOMAddChild, DOM Exception code: 4</p>
  
  <p>If I use XDOMCreateNode to create the TEST.CHILD element, the XDOMAddChild works fine.
  The only difference I can prove ids that the inserted node hanlde is different between teh 2 examples. The one that works the nodehandle is XDOM.ELEMENT.NODE (Type 1) and the one that fails in XDOM.DOC.NODE (Type 9).</p>
  
  <p>Not sure where to go from here. Any code snippets, links, pointers; greatly appreciated</p>