如何使用 php 获取 xml 节点的名为 xlink:href 的属性的值

发布于 2024-09-15 07:42:12 字数 856 浏览 3 评论 0原文

我就是做不到,不知道乳清。如何使用 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>

i just cant do it, dont kno whey. How can I get the value of an attribute called xlink:href of an xml node by using php. Please please someone just give me a nudge. i am new to php

This is the XML Document

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箜明 2024-09-22 07:42:12

使用 DOM*NS 函数之一,如 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 返回一个 节点列表,节点列表中的每一项都会属性。 getAttributeNS 页面上的文档有另一个示例。)

Use the DOM and one 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') );

(This is untested code; the print_r might not work as expected. getAttributeNS returns a node list, each item in the node list will be an attribute. The documentation on the getAttributeNS page has another example.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文