[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

(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 ?
0
LeeDerbyshire
Asked:
LeeDerbyshire
  • 4
  • 2
1 Solution
 
mvgeertruyenCommented:
getElementsByTagName("t:Value")[1] should do it. You are much better off querying this document using XPath however.

Hope it helps  
0
 
LeeDerbyshireAuthor Commented:
Do you have a pointer to a simple XPath example that would work in a situation like this?  I would like the be able to do something like:
getElementsByTagName("t:ExtendedFieldURI[PropertyTag="0x10f3"]/t:Value")
0
 
mvgeertruyenCommented:
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LeeDerbyshireAuthor Commented:
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:ExtendedFieldURI[@PropertyTag="0x10f3"]/t:Value")

but it doesn't.
0
 
LeeDerbyshireAuthor Commented:
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.
0
 
LeeDerbyshireAuthor Commented:
Okay, I have it:

//t:Value[ancestor::t:ExtendedProperty/t:ExtendedFieldURI/@PropertyTag=""0x1090""]

Doesn't work with GetElementsByTagName, though.  I have to use SelectSingleNode
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now