Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using xmldom to parse an xml file
Message
From
25/02/2003 10:18:06
Bob Tracy
Independent Consultant
Driftwood, Texas, United States
 
 
To
25/02/2003 01:35:05
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00757421
Message ID:
00757544
Views:
9
Hi Mark,

Here's a sample procedure I snipped from one of my apps, hope it helps:
PROTECTED PROCEDURE ReadSystem AS VOID
* Gets the OLEDB connection string and any other initialization parameters
* from the system.xml file.
LOCAL llOK,lcXPath,lcDef,oSysDoc
WITH THIS
	oSysDoc = CREATEOBJECT('MSXML2.DOMDocument.4.0')
	llOK = oSysDoc.load(SYS(5)+SYS(2003)+'\xml\system.xml')
	IF llOK
		* See which connection string we're using
		lcXPath = [oSysDoc.documentElement.selectSingleNode("//class]
		lcXPath = lcXPath+"[name='"+.cClassName+"']"
		IF EMPTY(EVALUATE(lcXPath+[/connstr").text]))
			lcDef = [oSysDoc.documentElement.selectSingleNode("]
			lcDef = lcDef+[defaultconnstr").text]
			lcServer = EVALUATE(lcXPath+[/server").text])
			lcDB = EVALUATE(lcXPath+[/database").text])
			.cConnStr = EVALUATE(lcDef)
			.cConnStr = .cConnStr+[data source=]+lcServer+[;initial catalog=]+lcDB+[;]
		ELSE
			.cConnStr = EVALUATE(lcXPath+[/connstr").text])
		ENDIF		
		* Set up an XPath statement for retrieval of system variables
		* Get the variable values
		.cTableName = EVALUATE(lcXPath+[/tablename").text])
		.cPrimaryKey = EVALUATE(lcXPath+[/primarykey").text])
		.cNameListFields = EVALUATE(lcXPath+[/namelistfields").text])
		.cNameListOrder = EVALUATE(lcXPath+[/namelistorder").text])
		.cNameListCueField = EVALUATE(lcXPath+[/namelistcuefield").text])
		.cBasePath = EVALUATE(lcXPath+[/basepath").text])
		.cSchemaFile = EVALUATE(lcXPath+[/schemafile").text])
		.cQuery = EVALUATE(lcXPath+[/query").text])
**		.cAppSpecific = EVALUATE(lcXPath+[/appspecific").text])
	ELSE	
		ERROR 'The system.xml file is missing or damaged'
	ENDIF
ENDWITH
ENDPROC
The file it parses looks like this:
<?xml version="1.0"?>
<system>
	<defaultconnstr>provider=SQLXMLOLEDB.3.0;data provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;
	</defaultconnstr>
	<classes>
		<class>
			<name>customer</name>
			<connstr></connstr>
			<server>DAVID</server>
			<database>Northwind</database>
			<tablename>customers</tablename>
			<primarykey>customerid</primarykey>
			<namelistfields>[companyname]</namelistfields>
			<namelistorder>[companyname]</namelistorder>
			<namelistcuefield>[companyname]</namelistcuefield>
			<basepath>C:\DEVELOPMENT\XMLFORMS\</basepath>
			<schemafile>customer.xsd</schemafile>
			<query>/customer[@customerid='</query>
		</class>
		<class>
			<name>department</name>
			<connstr></connstr>
			<server>DAVID</server>
			<database>Quality</database>
			<tablename>departments</tablename>
			<primarykey>pkid</primarykey>
			<namelistfields>[RTRIM(id)+' '+RTRIM(name)]</namelistfields>
			<namelistorder>[id]</namelistorder>
			<namelistcuefield>[name]</namelistcuefield>
			<basepath>C:\DEVELOPMENT\MSMQ\</basepath>
			<schemafile>department.xsd</schemafile>
			<query>/department[@pkid='</query>
		</class>
		<class>
			<name>employee</name>
			<connstr></connstr>
			<server>DAVID</server>
			<database>Quality</database>
			<tablename>employees</tablename>
			<primarykey>pkid</primarykey>
			<namelistfields>[RTRIM(firstname)+' '+RTRIM(lastname)]</namelistfields>
			<namelistorder>[lastname]</namelistorder>
			<namelistcuefield>[lastname]</namelistcuefield>
			<basepath>C:\DEVELOPMENT\MSMQ\</basepath>
			<schemafile>employee.xsd</schemafile>
			<query>/employee[@pkid='</query>
		</class>
	</classes>
</system>
Bob Tracy

Never engage in a battle of wits if you're only half armed.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform