Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error reading XML Cursor Nodes
Message
From
08/06/2023 08:49:27
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
To
08/06/2023 08:06:09
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01686709
Message ID:
01686713
Views:
42
Hi,

Your origin code replace loNode variable.
        loNode2 = loNode.selectSingleNode("ProductCode")
        ? loNode2.text
        messagebox(loNode2.text)
        replace ref WITH loNode2.text
		
        loNode2 = loNode.selectSingleNode("Quantity")
        ? loNode2.text
        messagebox(loNode2.text)
        replace qtt WITH VAL(loNode2.text)
MartinaJ

>Hello Comunity,
>
>I build this above code to read XML file and insert the value into Cursor:
>
>
>LOCAL loXMLDoc, loRoot, loNodes, loNode
>
>* Create a new DOMDocument object
>loXMLDoc = CREATEOBJECT("MSXML2.DOMDocument")
>
>* Load the XML file
>lcXMLFile = GETFILE("XML")
>IF !loXMLDoc.load(lcXMLFile)
>    ? "Error loading XML file:"
>    ? loXMLDoc.parseError.reason
>    RETURN
>ENDIF
>
>CREATE CURSOR crs ( ref C(18), qtt N(10,6)) 
>* Get the root element of the XML document
>loRoot = loXMLDoc.documentElement
>
>* Access multiple nodes using selectNodes
>loNodes = loRoot.selectNodes("//SourceDocuments/SalesInvoices/Invoice/Line")
>
>
>* Loop through the nodes using FOR EACH
>FOR EACH loNode IN loNodes
>    SELECT crs
>    APPEND BLANK
>
>        loNode = loNode.selectSingleNode("ProductCode")
>        ? loNode.text
>        messagebox(loNode.text)
>        replace ref WITH loNode.text
>		
>        loNode = loNode.selectSingleNode("Quantity")
>        ? loNode.text
>        messagebox(loNode.text)
>        replace qtt WITH VAL(loNode.text)
>    * Perform additional operations with the node, if needed
>
>ENDFOR
>
>SELECT crs
>BROWSE nowait
>
>
>But , if i use only :
>
>        loNode = loNode.selectSingleNode("Quantity")
>        ? loNode.text
>        messagebox(loNode.text)
>        replace qtt WITH VAL(loNode.text)
>
>the code work fine, but if have two , like this:
>
>        loNode = loNode.selectSingleNode("ProductCode")
>        ? loNode.text
>        messagebox(loNode.text)
>        replace ref WITH loNode.text
>		
>        loNode = loNode.selectSingleNode("Quantity")
>        ? loNode.text    && ERROR HERE
>        messagebox(loNode.text)
>        replace qtt WITH VAL(loNode.text)
>
>VFP , return on comment &&ERROR HERE with this message:
>LONODE is not an Object
>
>I don´t know why because i need on the same : loNodes = loRoot.selectNodes("//SourceDocuments/SalesInvoices/Invoice/Line"), other values to fill into my cursor.
>
>I send in attachement my XML file.
>
>
>Someone could give help !
>
>Many thanks,
>Luis

Hello Martina,

Thanks for your reply, are you saying that I cannot use lonode ?
Also, my For each return always the same values for each 3 lines and I don't no why?

Could you help me

Best regards
Luis

hi,
sorry, but can you please modify my coding to append in my cursor into columns ref and qtt with each line values of ProductCode and Quantity.
My difficulty are that productcode and Quantity return the same values I this case the first line vaues, then my cursor have 3 times the same line with same values.
I not feel comfortable to do that and it will be a great help for me!

Thanks
Luis
Previous
Reply
Map
View

Click here to load this message in the networking platform