tags:

views:

27

answers:

1

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"&gt;
    <topic id="1HLCM7CDQ-21WQN9G-66">
        <instanceOf>
            <subjectIndicatorRef xlink:type="simple" xlink:href="http://cmap.coginst.uwf.edu/#concept"/&gt;
        </instanceOf>
        <baseName>
            <baseNameString><![CDATA[feathers]]></baseNameString>
        </baseName>
        <occurrence>
            <resourceRef xlink:type="simple" xlink:href="file:/./Birds_concept - about birds/feathers.txt"/>
        </occurrence>
    </topic>
</topicMap>
+1  A: 

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.)

Charles
Thanks for very quick reply i will test it asap and report. I did try xpath DOM as well, right now i am using simplexml. i am going to try this code. thanks again a lot
Zero Cool
HI i am getting this error and i have no idea why Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1 in C:\xampp\htdocs\test.php on line 6line 6 is $doc->loadXML('Birds.xml');i appreciate the help. cheers
Zero Cool
if i load the xml file in the $doc->loadXML('Birds.xml'); it is giving error. but if i copy the whole content of xml files in a variable $stuff='all the xml'; $doc->loadXML($stuff); it works and gives me result.....its seems like since i have been working i have this problem
Zero Cool
Hi thanks it worked i was loading a file so i found out from documentation that i have to use $doc->load('birds.xml'); instead of $doc->loadXML('Birds.xml');Thanks a lot
Zero Cool