1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to access XML *attributes* using XPath

Discussion in 'Support' started by mscheuner, Feb 3, 2009.

  1. mscheuner

    Joined:
    May 21, 2008
    Messages:
    20
    Likes Received:
    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
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    mscheuner wrote:


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


    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
     
  3. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3

    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>
     
  4. mscheuner

    Joined:
    May 21, 2008
    Messages:
    20
    Likes Received:
    0
    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
     

Share This Page