Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-02-2012, 02:38 AM   PM User | #1
hermanpeckel
New to the CF scene

 
Join Date: Aug 2012
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
hermanpeckel is an unknown quantity at this point
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
hermanpeckel is offline   Reply With Quote
Old 08-02-2012, 02:42 AM   PM User | #2
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,428
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
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
Alex Vincent is offline   Reply With Quote
Users who have thanked Alex Vincent for this post:
hermanpeckel (08-02-2012)
Old 08-02-2012, 02:46 AM   PM User | #3
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 906
Thanks: 4
Thanked 212 Times in 211 Posts
tracknut is an unknown quantity at this point
I'm not an xpath wizard, but something like:
Code:
//od:XMPBlob/od:XMPItem[od:XMPItemName=ItemA]/od:XMPItemValue
Dave
tracknut is offline   Reply With Quote
Users who have thanked tracknut for this post:
hermanpeckel (08-02-2012)
Old 08-02-2012, 03:14 AM   PM User | #4
hermanpeckel
New to the CF scene

 
Join Date: Aug 2012
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
hermanpeckel is an unknown quantity at this point
Quote:
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
hermanpeckel is offline   Reply With Quote
Reply

Bookmarks

Tags
jdf, xml, xmp, xpaths

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:33 PM.


Advertisement
Log in to turn off these ads.