Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Produce XLS file from XML file problem
Message
From
05/07/2019 07:14:05
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
To
05/07/2019 06:25:05
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01669410
Message ID:
01669415
Views:
43
>I urgently need an help to generate an excel file from the XML file I attached.
>The problem is when the same invoice in XML has more than one row.
>I do not know how to write in the current code a While loop so that while the invoice does not change it adds a new line.
>I ask for your help and attach the XML file and the current excel file it produce, and also the excel i need to produce.
>

Luís,

Without using transformations or schemas, you can peek the different pieces of the invoice information and assemble them to produce the final XLS lines.

The SELECTs and BROWSEs are for checking purposes only. Replace them with code that will mount the line.
LOCAL XML AS MSXML2.DOMDocument60

m.XML = CREATEOBJECT("MSXML2.DOMDocument.6.0")

m.XML.Async = .F.
m.XML.Load(GETFILE())

LOCAL Invoices AS MSXML2.IXMLDOMNodeList
LOCAL Invoice AS MSXML2.IXMLDOMNode
LOCAL DocTotals AS MSXML2.IXMLDOMNode
LOCAL Details AS MSXML2.IXMLDOMNodeList
LOCAL Detail AS MSXML2.IXMLDOMNode

m.XML.Setproperty("SelectionNamespaces", 'xmlns:saft="urn:OECD:StandardAuditFile-Tax:PT_1.04_01"')

m.Invoices = m.XML.Selectnodes("//saft:SourceDocuments/saft:SalesInvoices/saft:Invoice")

FOR EACH m.Invoice IN m.Invoices

	XMLTOCURSOR("<vfp>" + m.Invoice.xml + "</vfp>", "tmpInvoiceHeader")
	SELECT tmpInvoiceHeader
	BROWSE

	m.DocTotals = m.Invoice.selectNodes("saft:DocumentTotals").item(0)

	XMLTOCURSOR("<vfp>" + m.DocTotals.xml + "</vfp>", "tmpInvoiceTotals")
	SELECT tmpInvoiceTotals
	BROWSE

	m.Details = m.Invoice.selectNodes("saft:Line")
	FOR EACH m.Detail IN m.Details

		XMLTOCURSOR("<vfp>" + m.Detail.xml + "</vfp>", "tmpInvoiceDetail")
		SELECT tmpInvoiceDetail
		BROWSE

	ENDFOR

ENDFOR
Hello António,

Thanks for reply and your great coding.
I need only just a little help, could you write the command to mount and create Excel file result for each line like my excel attach file named : saft_01-06-2019_30-06-2019_That i want produce.xml.zip ?

Best regards and many thanks,
Luis
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform