Welcome!

By registering with us, you'll be able to discuss, share and exchange private messages with other members of our community.

SignUp Now!

How to access XML *attributes* using XPath

May
20
0
Folks,
Let's say I have a XML fragment like this:

<Requester>
<ApplicationID application="OMS_SERVICE" bo="Client" />

How can I access the value of the "application" attribute in TakeCommand??

From what I can see, the XMLXPATH function in TCMD 9 (and from the looks of it - in TCMD 10, too) can only read and write element values - but not attributes.

Really?!?!? This seems like a severe limitation, really - XML documents typically are mixed collections of elements and attributes.

Or am I missing something here??

Cheers! Marc
 
mscheuner wrote:


> Let's say I have a XML fragment like this:
>
> <Requester>
> <ApplicationID application="*OMS_SERVICE*" bo="*Client*" />
>
> How can I access the value of the "application" attribute in TakeCommand??

You cannot; Take Command does not currently support retrieving XML
attributes.


>>From what I can see, the XMLXPATH function in TCMD 9 (and from the looks of it - in TCMD 10, too) can only read and write element values - but not attributes.
>
> Really?!?!? This seems like a severe limitation, really - XML documents typically are mixed collections of elements and attributes.
>
> Or am I missing something here??

I'll add it to the suggestion list for v11, but so far you're the only
user who's asked for it.

Rex Conn
JP Software
 
Folks,
Let's say I have a XML fragment like this:

<requester>
<applicationid application="<b>OMS_SERVICE</b>" bo="<b>Client</b>">

How can I access the value of the "application" attribute in TakeCommand??

From what I can see, the XMLXPATH function in TCMD 9 (and from the looks of it - in TCMD 10, too) can only read and write element values - but not attributes.

Really?!?!? This seems like a severe limitation, really - XML documents typically are mixed collections of elements and attributes.

Or am I missing something here??

Cheers! Marc


Here's a clue:

File X.XML :

<foo>
<bar>
<baz whatzit='frob'>
</baz>
</bar>
</foo>


> echo answer=%@xmlxpath[".\x.xml",foo/bar/baz/@whatzit]
answer=frob


You can access an attribute with the same syntax an item by prefixing the attribute name with an '@'.

Rex has disclaimed support for this, but I've been using it consistently without a problem.


</applicationid></requester>
 
Here's a clue:
> echo answer=%@xmlxpath[".\x.xml",foo/bar/baz/@whatzit]
answer=frob
You can access an attribute with the same syntax an item by prefixing the attribute name with an '@'.

Ah, yes - look at that - that's the standard XPath syntax, and I had tried it before (but that was still in TCMD v8 and it hadn't worked back then).

But now in TCMD v9, this works like a charm - thanks!

Rex: no need to consider for v11 - it's already in there :-)

Thanks guys
Marc
 

Similar threads

Back
Top