Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Insert new TAG in XML
Message
De
29/10/2021 09:41:03
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Insert new TAG in XML
Divers
Thread ID:
01682601
Message ID:
01682601
Vues:
63
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform