Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error reading XML Cursor Nodes
Message
From
08/06/2023 20:50:17
 
 
To
08/06/2023 17:46:15
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01686709
Message ID:
01686716
Views:
38
>>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
>
>try:
>
>loxmldoc = Createobject("MSXML2.DOMDocument")
>loxmldoc.Load("D:\_Escritorio\01686709.xml")
>lonodes = loxmldoc.selectnodes("//SourceDocuments/SalesInvoices/Invoice/Line")
>
>Create Cursor invoicelines ( LineNumber i,productcode N(10,0),productdescription c(15),quantity N(5,2),unitofmeasure c(3),unitprice N(18,16),taxpointdate d(8),Description c(60),creditamount N(4,2),tax c(15),taxexemptionreason c(20),taxexemptioncode c(3),settlementamount N(4,2) )
>
>For Each _line In lonodes
>  Xmltocursor( '<row>'+_line.XML+'</row>','InvoiceLines',8192)
>Endfor
>
>Browse
>
>
>Hi Março,
>
>Thanks for your reply, I see that you use
>
>For Each _line In lonodes
>  Xmltocursor( '<row>'+_line.XML+'</row>','InvoiceLines',8192)
>Endfor
>
>I have also fields for my header that have not rows. Can I use same technic with another cursor name for header field of my invoice?
>Many thanks
>Luis

Hello Luis.. yes.. though I should have used the term
<Invoice>
instead of
<row>
since a cursor to object takes the form of table.row[n].column[n] (
<table><row><column>
).

Just make sure you provide that xml structure to xmltocursor.
@nfoxdev
github.com/nfoxdev
Previous
Reply
Map
View

Click here to load this message in the networking platform