How can I get the value of an attribute called xlink: href from xml node using php

I just can not do this, I do not know the serum. How to get xlink: href attribute value from xml node using php. Please, please, someone will just push me. i am new to php

This is an 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> 
+4
source share
1 answer

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 unverified code; print_r may not work as expected. GetAttributeNS returns a node list , each element in a node will have an attribute . There is another example in the documentation on the getAttributeNS page.)

+2
source

All Articles