Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating XML File
Message
From
25/03/2019 19:16:27
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Creating XML File
Miscellaneous
Thread ID:
01667547
Message ID:
01667547
Views:
68
Hello community,

I want to create a XML file from SQL serve Cursor, then i build this script:
loXML = Createobject('MSXML2.DOMDocument')

loNode = loXML.createProcessingInstruction('xml','version="1.0" encoding="Windows-1252" standalone="yes"')

loXML.appendChild(loNode)

* Create the root "customers" element and add it to the XML.
loRoot = loXML.createElement('customers')
loXML.appendChild(loRoot)

*Scan

	loCust = loXML.createElement('customer')
	* Set the attributes.
	loCust.setAttribute('id',ASTR(fo.no))
	*loCust.appendchild('CUSTOMERID')
	loCust.setAttribute('company', Alltrim(fo.nome))
	loCust.setAttribute('contact', alltrim(fo.morada))
	loCust.setAttribute('city', Alltrim(fo.codpost))

	* Get the orders for the selected customer, then go through each order
	*and create the "order" element
	liCustID = fo.no

	TEXT TO msel TEXTMERGE NOSHOW PRETEXT 7
	Select fo.no [no], fo.docdata, fn.ref, fn.design, fn.qtt From fo (Nolock) inner join fn (Nolock)
		on fn.fostamp = fo.fostamp
		where no = 155 
		and fo.fostamp = ?fo.fostamp
	ENDTEXT
	
	IF u_sqlexec(msel,[CustOrders])
	Select CustOrders
		loOrder = loXML.createElement('order')

		* Set the attributes.
		loOrder.setAttribute('orderid',   fo.docdata)
		loOrder.setAttribute('orderdate', date())
		loOrder.setAttribute('reqdate',   date())
		* Add the order element to the customer element.
		loCust.appendChild(loOrder)
	
	Scan

		loOrderL = loXML.createElement('Linhas')

		* Set the attributes.
		loOrderL.setAttribute('ref',   fn.ref)
		loOrderL.setAttribute('design', fn.design)
		loOrderL.setAttribute('qtt', fn.qtt)
		* Add the order element to the customer element.
		*loCust.appendChild(loOrder), assim fica em linha com order,mesmo nivel.
		*Abaixo crio sub node de loOrder
		loOrder.appendChild(loOrderL)

	ENDSCAN
		* Add the customer element to the root customers element.
		loRoot.appendChild(loCust)
	Endif
*Endscan
* View the XML.
Strtofile(loXML.XML, 'd:\alixo\customerorders.xml')
Modify File "d:\alixo\customerorders.xml" Nowait
first problem :
the first line write only :
<?xml version="1.0" standalone="yes"?>
and not :
<?xml version="1.0" encoding="Windows-1252" standalone="yes"?>
second : the tag are write like this:
<customer id="155" company="company name" contact="Mr. VFP" city="UK">
, but i want with the following format:
<Customerid>155</Customerid>
<Company>MR.  VFP</Company>
<city>UK</city>
Someone could give help to solve this.
Many thanks,
Luis
Next
Reply
Map
View

Click here to load this message in the networking platform