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 11-12-2012, 11:15 PM   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
XPath Referencing Integer

Folks,

I've had some success with my XPath forays, mostly thanks to people on this site. I thought I'd try my luck again!

I need to access the value of the WIDTH attribute of the TRIM BOX in -

Code:
<od:PageBoxInfo ID="Link6">
<Page>
<PageBox BoxType="MediaBox" Width="610" Height="1280"/>
<PageBox BoxType="CropBox" Width="592" Height="1280"/>
<PageBox BoxType="BleedBox" Width="593" Height="1280"/>
<PageBox BoxType="ArtBox" Width="594" Height="1280"/>
<PageBox BoxType="TrimBox" Width="595" Height="1280"/>
</Page>
</od:PageBoxInfo>
...and I have tried to do this using the XPath -

//od:PageBoxInfo/Page/PageBox[@BoxType="TrimBox"]/@Width

but to no avail. Does this XPath look correct?

I was thinking that the result may have been returned to me as a string rather than an integer, but I'm not sure. I'm no XPath master!

Any ideas?

Thanks in advance
HP
hermanpeckel is offline   Reply With Quote
Old 11-13-2012, 02:11 AM   PM User | #2
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
Actually, I just noticed the double quotes (") in my XPath. I changed this to single quotes (') but still the same result.
hermanpeckel is offline   Reply With Quote
Old 11-16-2012, 07:57 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
I am getting error due to the od: in the xml file. This maybe your problem.

May I offer an easier method, simplexml. Remove both od: and this does what you want
PHP Code:
<?php
$xml 
simplexml_load_file("PageBox.xml");  // I made your code into a file named People.xml

$i 0;
foreach (
$xml->Page->PageBox as $PageBox[])
{
    if(
$PageBox[$i]->attributes()->BoxType == "TrimBox")
        echo 
"The Width you seek is: ".$PageBox[$i]->attributes()->Width "<br />";
    
$i++;
}
?>
sunfighter is offline   Reply With Quote
Old 11-18-2012, 09:50 PM   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
Thanks for your help Sunfighter. Unfortunately the XML is generated by another application we are working with and we have no option to change it. The XML is actually a Job Definition File (.jdf) and contains about 2000 lines of code (most of it useless).

It's interesting what you say about the "od:" as this appears in a lot of the file. Is there a way I can reference things without the "od:"?
hermanpeckel is offline   Reply With Quote
Old 11-19-2012, 06:37 AM   PM User | #5
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Maybe you could try something like this first
PHP Code:
<?php
$string 
file_get_contents("PageBox.jdf");
$string str_replace("od:"""$string);
file_put_contents("PageBox.xml"$string);
?>
And then run what I gave you before. I don't know the real names for your files so adjust accordingly.
sunfighter is offline   Reply With Quote
Old 11-19-2012, 02:34 PM   PM User | #6
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,863
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
I don’t think it’s a good idea to manually remove an XML namespace, they are there for a reason.

to the original problem: the XPath so far is correct, but the od namespace must be known to the XPath interpreter (which obviously depends on the interpreter used, XSLT is different from SimpleXML is different from DOMDocument, etc.)

the return type of the XPath expression is usually a string for primitive data types (maybe except for the XPath functions), though that may also depend on the interpreter used.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 11-20-2012, 10:54 PM   PM User | #7
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
Thanks for your input guys!

I just heard back from our software developers who support the product that uses the Xpath info. Apparently the software does not support Xpath 2.0, and only supports a subset of Xpath 1.0, and they can't tell me what that subset is.

I assume this is what is making things difficult (or impossible). Sorry to waste your time guys.

Regards

HP
hermanpeckel is offline   Reply With Quote
Reply

Bookmarks

Tags
attribute, integer, trimbox, xpath

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 03:20 AM.


Advertisement
Log in to turn off these ads.