LeeDerbyshire
asked on
(Advanced?) GetElementsByTagName question
Suppose part of my XML response looks like this:
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="0x3fd9" PropertyType="String" />
<t:Value>Hello 1</t:Value>
</t:ExtendedProperty>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="0x10f3" PropertyType="String" />
<t:Value>Hello 2</t:Value>
</t:ExtendedProperty>
How can I use getElementsByTagName to get the second value? If I use "t:Value", I get the first one, of course, but how can I use the PropertyTag value to tell it that I want the second t:Value ?
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="0x3fd9" PropertyType="String" />
<t:Value>Hello 1</t:Value>
</t:ExtendedProperty>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="0x10f3" PropertyType="String" />
<t:Value>Hello 2</t:Value>
</t:ExtendedProperty>
How can I use getElementsByTagName to get the second value? If I use "t:Value", I get the first one, of course, but how can I use the PropertyTag value to tell it that I want the second t:Value ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sure; here are a couple of examples:
http://snippets.dzone.com/posts/show/5272
http://www.w3schools.com/xpath/xpath_examples.asp
http://snippets.dzone.com/posts/show/5272
http://www.w3schools.com/xpath/xpath_examples.asp
ASKER
Sorry to seem so dense, but I just can't seem to get it working. From what I've read, this should work:
getElementsByTagName("t:Ex tendedFiel dURI[@Prop ertyTag="0 x10f3"]/t: Value")
but it doesn't.
getElementsByTagName("t:Ex
but it doesn't.
ASKER
Ugh, I just noticed a small, but significant, complication. The t:ExtendedFieldURI field has a closing / within the tag. Which, of course, means that t:Value isn't a child of it (obvious, now). I think I need to use it's ancestor - I'll see what I can find out about it.
ASKER
Okay, I have it:
//t:Value[ancestor::t:Exte ndedProper ty/t:Exten dedFieldUR I/@Propert yTag=""0x1 090""]
Doesn't work with GetElementsByTagName, though. I have to use SelectSingleNode
//t:Value[ancestor::t:Exte
Doesn't work with GetElementsByTagName, though. I have to use SelectSingleNode
ASKER
getElementsByTagName("t:Ex