Getting Unexpected xpath results

Here is the source xml: xmlThis is the xml of an fxg file produced by Adobe. The FXG document is valid xml, and it basically contains all the information for a document that can be edited. This specific question pertains to text that can be changed within the FXG so that the content can change.I'm tryng to grab all the RichText elements and attributes within that element that have an attribute of s7:elementID using xpath relative location. The source XML only has three total RichText elements, with only two of them having a s7:elementID<?php$url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&fmt=fxgraw"; $xml = simplexml_load_file($url); $xml->registerXPathNamespace('default', 'http://ns.adobe.com/fxg/2008');$xml->registerXPathNamespace('s7', 'http://ns.adobe.com/S7FXG/2008');$textNode = $xml->xpath("//default:RichText/@s7:elementID");print("<pre>".print_r($textNode,true)."</pre>");?>I got this far with help from another question. But the returned array is not what I was expecting. setting the xpath as I did, I am expecting it to select all the RichText elements that have an s7:elementID, as well as the other attributes of that element. However, it isn't grabbing any of the other attributes of those elements. here is what it outputs:Array( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [elementID] => smalltext ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [elementID] => largetext ) ))If I take the exact same php but change the xpath like so:$textNode = $xml->xpath("//default:RichText");I get this array result:Array( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [x] => 278.418 [y] => 115.542 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Trade Gothic LT Pro Bold Cn [fontSize] => 11 [color] => #518269 [whiteSpaceCollapse] => preserve [width] => 212.582 [height] => 33 ) [content] => SimpleXMLElement Object ( [p] => Array ( [0] => SimpleXMLElement Object ( [span] => Scott, Anna, and Conner ) [1] => SimpleXMLElement Object ( [span] => and our little one on the way ) ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [x] => 278.998 [y] => 86.7168 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Bootstrap [fontSize] => 19 [color] => #518269 [whiteSpaceCollapse] => preserve [trackingRight] => 4% [width] => 240 [height] => 29 ) [content] => SimpleXMLElement Object ( [p] => SimpleXMLElement Object ( [span] => THE JOHNSONS ) ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [x] => 278.418 [y] => 77.2373 [columnGap] => 0 [columnCount] => 1 [textAlign] => left [fontFamily] => Trade Gothic LT Pro Bold Cn [fontSize] => 11 [color] => #518269 [whiteSpaceCollapse] => preserve ) [content] => SimpleXMLElement Object ( [p] => SimpleXMLElement Object ( [span] => Array ( [0] => W [1] => ishing you the best this season. ) ) ) ))If you notice, the first two array items don't even have the info for the s7:elementID, but they are the two that should. The third does not have a s7:elementID by design.Can anyone explain why I am getting these unexpected array results, with some attributes showing up, and others not?UPDATEPer dusan, i updated the php to:$textNode = $xml->xpath("//default:RichText[@s7:elementID]");Now the array only returns attributes of the element that do not have a prefix. I need all attributes, prefix and not.Array( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [x] => 278.418 [y] => 115.542 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Trade Gothic LT Pro Bold Cn [fontSize] => 11 [color] => #518269 [whiteSpaceCollapse] => preserve [width] => 212.582 [height] => 33 ) [content] => SimpleXMLElement Object ( [p] => Array ( [0] => SimpleXMLElement Object ( [span] => Scott, Anna, and Conner ) [1] => SimpleXMLElement Object ( [span] => and our little one on the way ) ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [x] => 278.998 [y] => 86.7168 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Bootstrap [fontSize] => 19 [color] => #518269 [whiteSpaceCollapse] => preserve [trackingRight] => 4% [width] => 240 [height] => 29 ) [content] => SimpleXMLElement Object ( [p] => SimpleXMLElement Object ( [span] => THE JOHNSONS ) ) ))UPDATE 2changing the php to this seems to get all the attributes, both default and with the s7 prefix:<?php$url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&fmt=fxgraw"; $xml = simplexml_load_file($url); $xml->registerXPathNamespace('default', 'http://ns.adobe.com/fxg/2008');$xml->registerXPathNamespace('s7', 'http://ns.adobe.com/S7FXG/2008');$textNode = $xml->xpath("//default:RichText[@s7:elementID]"); // //default:RichText[@s7:elementID]/@*function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }foreach($textNode as $node){ pr($node->attributes('http://ns.adobe.com/S7FXG/2008')); pr($node->attributes());}?>And the XML Result:SimpleXMLElement Object( [@attributes] => Array ( [caps] => none [colorName] => [colorValue] => #518269 [colorspace] => rgb [elementID] => smalltext [fill] => true [fillOverprint] => false [firstBaselineOffset] => ascent [joints] => miter [maxFontSize] => 11 [miterLimit] => 4 [referencePoint] => inherit [rowCount] => 1 [rowGap] => 18 [rowMajorOrder] => true [stroke] => false [strokeOverprint] => false [warpBend] => 0.5 [warpDirection] => horizontal [warpHorizontalDistortion] => 0 [warpStyle] => none [warpVerticalDistortion] => 0 [weight] => 1 ))SimpleXMLElement Object( [@attributes] => Array ( [x] => 278.418 [y] => 115.542 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Trade Gothic LT Pro Bold Cn [fontSize] => 11 [color] => #518269 [whiteSpaceCollapse] => preserve [width] => 212.582 [height] => 33 ))SimpleXMLElement Object( [@attributes] => Array ( [caps] => none [colorName] => [colorValue] => #518269 [colorspace] => rgb [elementID] => largetext [fill] => true [fillOverprint] => false [firstBaselineOffset] => ascent [joints] => miter [maxFontSize] => 19 [miterLimit] => 4 [referencePoint] => inherit [rowCount] => 1 [rowGap] => 18 [rowMajorOrder] => true [stroke] => false [strokeOverprint] => false [warpBend] => 0.5 [warpDirection] => horizontal [warpHorizontalDistortion] => 0 [warpStyle] => none [warpVerticalDistortion] => 0 [weight] => 1 ))SimpleXMLElement Object( [@attributes] => Array ( [x] => 278.998 [y] => 86.7168 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Bootstrap [fontSize] => 19 [color] => #518269 [whiteSpaceCollapse] => preserve [trackingRight] => 4% [width] => 240 [height] => 29 ))now that it is able to retrieve all the attributes of the RichText element. How can I store certain attributes as a specific variable? For example, how can I set a variable for the s7:elementID and the fontSize attributes?
 
Back
Top