> -----Original Message-----
> From: realbasic-nug-bounces at lists dot realsoftware dot com
> [mailto:realbasic-nug-bounces at lists dot realsoftware dot com]On Behalf Of
> Trausti Thor Johannsson
> Sent: Saturday, December 29, 2007 2:20 PM
> To: REALbasic NUG
> Subject: XML noob help
>
>
> I appreciate any help I can get. Here is a result from xql query
>
> Code:
> ....
> <person>
> <name>Jack Johnes</name>
> <address>16000 Philadelphia Avenue</address>
> </person>
> <person>
> <name>John Taylor</name>
> <address>10 Downing Street</address>
> </person>
> ....
>
>
> Now, I traverse the results with
>
> Code:
> for i = 0 to personxml.length-1
> editfield1.text = editfield1.text + personxml.Item(i).??getname
> <---- To get the name
> editfield1.text = editfield1.text + personxml.item(i).??getaddress
> <--- to get the address
> next
>
Break it down:
personxml.Item(0) =
<person>
<name>Jack Johnes</name>
<address>16000 Philadelphia Avenue</address>
</person>
This xmlNode has 2 child nodes
personxml.Item(0).Child(0) =
<name>Jack Johnes</name>
personxml.Item(0).Child(1) =
<address>16000 Philadelphia Avenue</address>
The first Child has a single child, an xmlTextNode, whose value is "Jack
Johnes".
So, for any personxml.Item(i), the name is
personxml.Item(i).Child(0).Child(0).Value
and the address is
personxml.Item(i).Child(1).Child(0).Value
You could use another XQL to get the nodes by name instead of index, it
doesn't simplify the code much, but it does make it not dependent on the
order of the nodes.
namexml = personxml.item(i).xql("name")
name = namexml.item(0).Child(0).Value
HTH,
Tim
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.11/1201 - Release Date: 12/28/2007
11:51 AM
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|