Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Produce XLS file from XML file problem
Message
From
09/07/2019 19:20:29
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
To
09/07/2019 19:11:15
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01669410
Message ID:
01669485
Views:
40
>>>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.
>>
>Hello António,
>
>I have a problem because i need to pass to my excel file the content of TAG :
>ShipTo/Address
>I need information for TAGs, StreetName + AddressDetail + City + PostalCode + Region + Country.
>And Also the content of TAG Tax With information of : TaxCountryRegion + TaxPercentage.
>
>I try to do some changes on your code but without sucess.
>

Luís,

What was inserted to gather the information that you require is preceded by a "NEW" comment.

You must understand what is being done or else you'll need to come back here whenever you require extra data from the XML, and that does not make much sense.

I hope that this extended version will help you with that. In any case, I prefer to discuss the process and help you understand how to extend and adapt to your requirements.
* this is just a subset of the line, just complete with the rest
* NEW: added AddressDetail and TaxPercentage
CREATE CURSOR xlsOutput (InvoiceNo Varchar(32), SystemEntryDate Datetime, ;
	productCode Varchar(50), productDescription Varchar(200), ;
	taxpayable Double, grosstotal Double, ;
	taxpercentage Double, addressdetail Varchar(200))

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

* NEW: Address and TAX information in the XML file
LOCAL Address AS MSXML2.IXMLDOMNode
LOCAL Tax AS MSXML2.IXMLDOMNode

LOCAL FromHeader AS Object
LOCAL FromTotals AS Object
LOCAL FromDetail AS Object

* NEW: Address and TAX information VFP buffers
LOCAL FromAddress AS Object
LOCAL FromTax AS Object

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")
	SCATTER NAME FromHeader

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

	XMLTOCURSOR("<vfp>" + m.DocTotals.xml + "</vfp>", "tmpInvoiceTotals")
	SCATTER NAME FromTotals

	* NEW: select Address node from the invoice and store the data in a VFP buffer
	m.Address = m.Invoice.selectNodes("saft:ShipTo/saft:Address").item(0)
	XMLTOCURSOR("<vfp>" + m.Address.xml + "</vfp>", "tmpInvoiceShipTo")
	SCATTER NAME FromAddress

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

		XMLTOCURSOR("<vfp>" + m.Detail.xml + "</vfp>", "tmpInvoiceDetail")
		SCATTER NAME FromDetail

		* NEW: select tax information from the detail and store the data in a VFP buffer
		m.Tax = m.Detail.selectNodes("saft:Tax").item(0)
		XMLTOCURSOR("<vfp>" + m.Tax.xml + "</vfp>", "tmpTax")
		SCATTER NAME FromTax
 
		SELECT xlsOutput
		APPEND BLANK
		GATHER NAME m.FromHeader
		GATHER NAME m.FromTotals
		GATHER NAME m.FromDetail

		* NEW: fetch data from VFP buffers
		GATHER NAME m.FromAddress
		GATHER NAME m.FromTax

	ENDFOR

ENDFOR

SELECT xlsOutput
BROWSE
Hello António,

Your are almost there Tax is OK, but Address are in one column :
Rua dos Barbeitos n 335 Hab 1.1 4400-377 Vila Nova de Gaia
i need to create these columns in Excel:
StreetName + AddressDetail + City + PostalCode + Region + Country
Theses columns are chields of Address TAG.

Please save my day..!!

Best regards,
Luis
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform