Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Referencing XML with XPath

    Folks,

    A bit of a newbie question I'm hoping someone may be able to answer. We are using a system that writes job values into a JDF file (basically an XML file). We then need to read the data out of this file at gateways using XPaths.

    The problem is that the XML is written (by the application) in a bit of a weird way. Instead of having unique tags, the tags repeat. Example -
    Code:
    <od:XMPBlob>
    
    <od:XMPItem>
    <od:XMPItemName>ItemA</od:XMPItemName>
    <od:XMPItemValue>ValueA</od:XMPItemValue>
    </od:XMPItem>
    
    <od:XMPItem>
    <od:XMPItemName>ItemB</od:XMPItemName>
    <od:XMPItemValue>ValueB</od:XMPItemValue>
    </od:XMPItem>
    
    </od:XMPBlob>
    Firstly, is this normal? As in having common tag names?

    So the problem comes when trying to reference data from this XML using XPaths. The only way I have got it to work is like this -

    //od:XMPBlob/od:XMPItem[1]/od:XMPItemValue

    This will get the value of the 1st item in the list. The problem is, the items are never in exactly the same order. I need to know how to reference the items via an XPath based on the XMPItemName.

    That is, I want to get the value of XMPItemName:ItemA. Does anyone know how to do this using XPaths?

    Any pointers no matter how general are much appreciated!!

    Regards

    HP
    Last edited by Alex Vincent; 08-02-2012 at 02:40 AM. Reason: adding code tags

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    I can tell you that yes, this is perfectly normal for XML.

    Also, for your XPath question, this might help: http://zvon.org/comp/r/tut-XPath_1.h...tribute_values

    Zvon.org usually has had a good XPath tutorial here.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • Users who have thanked Alex Vincent for this post:

    hermanpeckel (08-02-2012)

  • #3
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,263
    Thanks
    10
    Thanked 277 Times in 276 Posts
    I'm not an xpath wizard, but something like:
    Code:
    //od:XMPBlob/od:XMPItem[od:XMPItemName=ItemA]/od:XMPItemValue
    Dave

  • Users who have thanked tracknut for this post:

    hermanpeckel (08-02-2012)

  • #4
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I'm not an xpath wizard
    Oh yes you are tracknut!! That was it! You have no idea how happy this makes me!!

    And thanks for the "teaching me how to fish" link Alex. I now have a bit of an idea of how xpaths work (which is a lot more than I had before).

    Thanks again gents!!

    Regards
    HP


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •