你如何通过php中的xml_file_open传递sodipodi作为属性?

时间:2012-05-08 13:00:26

标签: php xml svg

我的程序有效地尝试做的是从xml文件(以前是svg文件)中获取数据。并使用此方法从xml标记中获取相关信息作为属性和值。 我有这样的php设置

foreach($xml_file_open->g->path[0]->attributes() as $attribute => $value)
{
echo $attribute => $value
}

并且xml_file_open属性请求的输出是

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行风格和d故意拆分以便于阅读) 而不是获取这3行数据,我试图获取此标记内的所有内容

<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" />

它似乎是sodipodi:它不会作为属性读取,我怎么能读取sodipodi:cx / cy等作为属性?

2 个答案:

答案 0 :(得分:1)

“sodipodi:” - 属性名称的一部分是名称空间前缀。你怎么读XML?如果您使用DOM API,前缀可用through the DOMNode class

答案 1 :(得分:1)

将名称空间URI传递给attributes方法以访问前缀属性:

$attrs = $node->attributes('http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd');
echo $attrs['cx'];

更多信息:http://us3.php.net/manual/en/simplexmlelement.attributes.php