php - 如何获取名为 xlink :href of an xml node by using php 的属性的值

标签 php xml xlink

我就是做不到,不知道乳清。如何使用 php.ini 获取 xml 节点的名为 xlink:href 的属性的值。请有人给我一个轻推。我是 php 新手

这是 XML 文档

<?xml version="1.0" encoding="UTF-8"?>
<topicMap id="1HLCM3FXT-28MTV0W-50"
    xmlns="http://www.topicmaps.org/xtm/1.0/" xmlns:xlink="http://www.w3.org/1999/xlink">
    <topic id="1HLCM7CDQ-21WQN9G-66">
        <instanceOf>
            <subjectIndicatorRef xlink:type="simple" xlink:href="http://cmap.coginst.uwf.edu/#concept"/>
        </instanceOf>
        <baseName>
            <baseNameString><![CDATA[feathers]]></baseNameString>
        </baseName>
        <occurrence>
            <resourceRef xlink:type="simple" xlink:href="file:/./Birds_concept - about birds/feathers.txt"/>
        </occurrence>
    </topic>
</topicMap>

最佳答案

使用the DOMone of the *NS functions, like getAttributeNS :

$doc = new DOMDocument();
$doc->loadXML($your_xml_string);
$resource_refs = $doc->getElementsByTagName('resourceRef');
foreach($resource_refs as $rr)
    print_r( $rr->getAttributeNS('http://www.w3.org/1999/xlink', 'href') );

(这是未经测试的代码;print_r 可能无法按预期工作。getAttributeNS 返回一个 node list,节点列表中的每一项都将是 an attribute。getAttributeNS 页面上的文档还有另一个示例。)

关于php - 如何获取名为 xlink :href of an xml node by using php 的属性的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3542153/

相关文章:

java - 在 SAXParser 中捕获部分 XML 代码的方法

java - 如何在Java中使用indexOf

php curl 多错误处理程序

javascript - 中止之前的ajax请求但有延迟吗?

php - GCM 与 PHP(谷歌云消息)

javascript - 如何使嵌入在 HTML 中的 SVG 加载其 xlink :href dependencies?

php - 在 Wordpress 中发布帖子并根据自定义字段元填充字段时运行 SQL 函数

java - 我可以使用 JAXB 将所有 namespace 定义放入顶级元素吗

jaxb - 如何强制 JAXB 编码器使用 xlink 引用?