Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading XML with detailed information 1

Status
Not open for further replies.

FateFirst

Programmer
Apr 15, 2002
212
GB
Hi.

I dont expect a solution as such but maybe just to be pointed to an area which contains enough information for me to get going. Most of the information I have read tends to be about writing XML and/or basic reading of XML files.

Here is a sample of the XML data:

Code:
<result>
	<header>
		<head name="Item1" value="Blah blah"/>
		<head name="Item2" value="Blah blah"/>
		<head name="Item3" value="Blah blah"/>
		<head name="Item4" value="Blah blah"/>
		<head name="Item5" value="Blah blah"/>
	</header>
	<status>
		<condition>ok</condition>
		<code>-1</code>
		<message>request completed successfully</message>
		<timestamp>1154346698</timestamp>
	</status>
	<properties result-num="4" total-rec="4">
		<property ref="1" status="Available" rent="0" sale="1" saletype="Off Plan" exclusive="1" bedrooms="4" propertytype="Detached Villa">
			<abstract>Descriptive text goes here.</abstract>
			<image>[URL unfurl="true"]http://www.website.com/image1.jpg</image>[/URL]
			<flag>[URL unfurl="true"]http://www.website.com/flag1.jpg</flag>[/URL]
		</property>
		<property ref="2" status="Available" rent="0" sale="1" saletype="Off Plan" exclusive="1" bedrooms="4" propertytype="Detached Villa">
			<abstract>Descriptive text goes here.</abstract>
			<image>[URL unfurl="true"]http://www.website.com/image2.jpg</image>[/URL]
			<flag>[URL unfurl="true"]http://www.website.com/flag2.jpg</flag>[/URL]
		</property>
		<property ref="3" status="Available" rent="0" sale="1" saletype="Off Plan" exclusive="1" bedrooms="4" propertytype="Detached Villa">
			<abstract>Descriptive text goes here.</abstract>
			<image>[URL unfurl="true"]http://www.website.com/image3.jpg</image>[/URL]
			<flag>[URL unfurl="true"]http://www.website.com/flag3.jpg</flag>[/URL]
		</property>
	</properties>
</result>

Basically I have an ASP page with a search properties box. A user can simply select various items from drop downs and click 'Search'. It then submits and XML request to an API server which then returns something like the above.

Once returned I would like to be able to format the result in a readable manner.

The only information I need is within each <property> tag (ie. <abstract>,<image>,<flag> etc) aswell as all the sub-information within the tag itself (ie. ref, status, rent etc).

I know getting the tag information is possible but im not totally sure on the sub-information.

Here is what I quickly have for my response code:
Code:
Set objXML=Server.CreateObject("Microsoft.XMLDOM")

strXML = "" '# See sample XML data above
objXML.async = False
objXML.loadXML (strXML)
	
for each x in objXML.documentElement.selectNodes("/result/properties/property")
	response.write("<b>" & x.nodename & "</b>")
	response.write(": ")
	response.write("<xmp>" & x.text & "</xmp><br>")
next
response.write("<hr>")
Response.Write("<xmp>" & objXML.xml & "</xmp>")

Any help would be appreciated.

- FateFirst
 
[tt] [red]'[/red]response.write("<xmp>" & x.text & "</xmp><br>")
[blue]for each y in x.childNodes
'your call
next[/blue]
[/tt]
 
Thanks tsuji!

I actually had that earlier but used it in the wrong section which is why I wasnt receiving the correct data.

That said, what would then be the best way to receive the sub-information:

Code:
<property ref="1" status="Available" rent="0" sale="1" saletype="Off Plan" exclusive="1" bedrooms="4" propertytype="Detached Villa">

Guess this sort of thing would need some asp/vb coding to gain this data.

Thanks again!

- FateFirst
 
Like this the essential is.
[tt]
for each x in objXML.documentElement.selectNodes("/result/properties/property")
response.write("<b>" & x.nodename & "</b>")
response.write(": " & "<br />")
response.write "-child nodes-<br />"
for each y in x.childnodes
response.write y.nodename & " : " & y.text & "<br />"
next
response.write "-attributes-<br />"
for each z in x.attributes
response.write z.nodename & " : " & z.nodevalue & "<br />"
next
next
[/tt]
Just mentally, visually may not pretty.
 
Thats perfect!

Thanks Tsuji! I really appreciate your help on this.

Take care!

- FateFirst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top