Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Insert new TAG in XML
Message
From
29/10/2021 11:33:02
 
 
To
29/10/2021 09:41:03
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01682601
Message ID:
01682602
Views:
52
Luís, you must specify the namespace of the OrderReference element or query for the local name. Either one of these will work and the execution of the code won't trigger the first error and the others that depend on it.

a) using the element namespace:
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.

>Hello comunity,
>
>I read this article at : http://www.robsprogrammingjunk.com/2006/05/vfp-inserting-nodes-with-xml-object.html?m=1
>where i can see this example:
>
>
>* 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.
>but unfortunately the code presented above gives me several errors, of which:
>
>Member ITEM does not evaluate to an object. (error 1)
>Property OBJCHILDNODES is not found.(error 2)
>Alias 'STRNODE' is not found.(error 3)
>Member ITEM does not evaluate to an object.(error 4)
>Nesting error . (error 5
>Nesting error . (error 6)
>
>Someone could give some help.
>Many thanks,
>Luis
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform