>>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 >>>>
>> 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:
>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 >>
>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?
<Invoice>instead of
<row>
since a cursor to object takes the form of table.row[n].column[n] (<table><row><column>).