我正在使用DOMDocument来读取XML(SVG),其中有名称空间。 我遍历所有节点的属性,但我似乎无法获取根元素的'xmlns'类型属性。DOMDocument xmlns属性 - 如何获取它们?
的XML看起来是这样的:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.48.1 "
viewBox="0,0 534,616"
...
>
当我尝试的东西艾克这样的:
$node= DOMDocument->documentElement;
foreach($node->attributes as $attribute) {
echo $attribute->nodeName."\n";
}
我得到了 '其他' 属性,如ID,视框等,但不xlmns :dc等。
有没有办法让他们呢?
请参阅http://stackoverflow.com/questions/2572365/enumerate-registered-namespaces-of-a-php-domdocument-object – 2011-06-09 15:11:48
所以不可能不使用simplexml再读取整个xml?我需要像读取它一样重现XML。我觉得很奇怪,这是不可能的,DOMDocument ... – Dylan 2011-06-09 15:26:07
你可以从一个特定的前缀到其关联的URI,反之亦然,但是,是的,ext/dom没有一个函数或属性获取您*全部*文档或节点中使用的名称空间。 – 2011-06-09 15:29:04