On 06/02/2009 02:15 AM, acpir wrote:
> All apologies if this is a really obvious question but after 3+ hours
> searching this group and the tubes in general I couldn't find the
> answer.
>
> I have xml data that looks like this:
> <root>
> <item>
> <item-description>a</item-description>
> <item-weight>5</item-weight>
> <item-color>blue</item-color>
> </item>
> </root>
>
> The data is in a document object and I've retrieved the node "item".
>
> I want to retrieve the value of item-weight. The element isn't always
> the second child and doesn't always exist.
Not a problem...
> From what I can tell by
> reading the docs I would have to retrieve the node list containing all
> of the children of item, test each one to see if it was named "item-
> weight", the retrieve the value of the node that tests positive.
>
No. Use getElementsByTagName liberally. Here's one possible scenario
1. Find the nodes named "root": getElementsByTagName("root"). Yes, I
know this will be a list of one entry.
2. for the next node in 1, find the nodes named "item":
getElementsByTagName("item"). Remember this nodeList.
3. for the next node in 2:, find the elements named "item-weight":
getElementsByTagName("item-weight"). Lather, rinse, repeat. At end
of list 2, return to step 2
If this doesn't float your boat, consider more pre-processing on your
server: use JSON and JSON overlay types on the client side.
> Please tell me there is a more efficient way to do his because I'm
> pretty sure there would be performance issues when this operation has
> to be performed a few dozen (few hundred) times.
>
GWT doesn't (yet) have a reliable cross-browser XML query language
implementation. There may be one in the incubator or other GWT-related
sites.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---