Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Insert new TAG in XML
Message
De
29/10/2021 12:03:26
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
À
29/10/2021 11:33:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01682601
Message ID:
01682603
Vues:
35
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

Hello António,

I hope all is well with you , and thanks again for the tip.

Best regards,
Luis
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform