m.xmlDoc.SetProperty("SelectionNamespaces", 'xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"') m.oNode = m.xmlDoc.SelectNodes("//cac:OrderReference")b) using an XPath function to retrieve element names, regardless of their namespace:
m.oNode = m.xmlDoc.SelectNodes("//*[local-name() = 'OrderReference']")
My advice? Always use the namespace selection.>* OPEN MSXML Object >xmlDoc=CREATEOBJECT("Msxml2.DOMDocument.6.0") >xmlDoc.ASYNC="false" >xmlDoc.LOAD(""C:\CIUS\ft00100000000262021.xml"") >x=xmlDoc.documentElement > >* INit document fragment >docFrag = xmlDoc.CreateDocumentFragment() > >* Set the XML >docFrag.appendChild(xmlDoc.CreateElement("REF_J")) > >* Obtain Original Node where children Exist >oNode=xmlDoc.selectnodes("/OrderReference") >i=0 >* Object Creation Of children nodes to iterate >objChildNodes = oNode.ITEM(0).childNodes && (error 1) >* Iterate through children, identify the node you want to insert before >FOR EACH strNode IN objChildNodes &&(error 2) > ** NODE IDENTIFIED, DO INSERT > IF strNode.nodename="REF_K" &&(error 3) > * Inserting at the location of the node with children, insert before the location of the child node. > oNode.ITEM(0).insertBefore(docFrag, oNode.ITEM(0).childNodes.ITEM(i)) &&(error 4) > EXIT FOR && (Error 5) > ENDIF > i=i+1 >NEXT &&(error 6) > >* Save XML >xmlDoc.SAVE("xmltest-output.xml") >>because the XML file are not available, i decide to use for testing purpose my XML file UBL (in attachment), where i try to add a new node.