Reputation: 305
what my program effectively is attempting to do is grab data from an xml file (that used to be an svg file). and with this grab the relevant information from the xml tags as attributes and values. I have my php set like this
foreach($xml_file_open->g->path[0]->attributes() as $attribute => $value)
{
echo $attribute => $value
}
and the output for the xml_file_open attributes request is
style="fill:#ff0000;fill-rule:evenodd;stroke:#000000;
stroke-width:1px;stroke-linecap:butt;stroke-linejoin:
miter;stroke-opacity:1"
id="path2987"
d="m 631.42859,603.79077 a 212.85715,162.85715 0 1 1
-425.7143,0 212.85715,162.85715 0 1 1 425.7143,0 z"
(3 lines with style and d being intentionally split for readability) whereas instead of getting those 3 lines of data I am attempting to get everything within this tag
<path
sodipodi:type="arc"
style="fill:#ff0000;fill-rule:evenodd;stroke:#000000;stroke-width:1px;
stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="path2987"
sodipodi:cx="418.57144"
sodipodi:cy="603.79077"
sodipodi:rx="212.85715"
sodipodi:ry="162.85715"
d="m 631.42859,603.79077 a 212.85715,162.85715 0 1 1
-425.7143,0 212.85715,162.85715 0 1 1 425.7143,0 z" />
it seems to be the sodipodi: that it won't read as an attribute, how would I get it to read sodipodi:cx/cy etc as an attribute?
Upvotes: 1
Views: 439
Reputation: 124179
Pass the namespace URI to the attributes method to access prefixed attributes:
$attrs = $node->attributes('http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd');
echo $attrs['cx'];
More info at: https://www.php.net/manual/en/simplexmlelement.attributes.php
Upvotes: 1
Reputation: 111349
The "sodipodi:"-part of the attribute name is the namespace prefix. How do you read the XML? If you use the DOM API the prefix is available through the DOMNode class.
Upvotes: 1