Hi I'm having a problem getting the value of an attribute in an xml file using namespaces.
<module name="ietf-inet-types" xmlns="urn:ietf:params:xml:ns:yang:yin:1" xmlns:inet="urn:ietf:params:xml:ns:yang:ietf-inet-types"> <namespace uri="urn:ietf:params:xml:ns:yang:ietf-inet-types"/> <prefix value="inet"/> </module> I want to get "inet" as the result of my xpath. I used this link Xpath to select value of sibling attribute with namespace as a reference and came up with:
$xml->xpath('/n:module/n:prefix/@n:value'); where n is the namespace prefix. However I'm getting an empty array as a result, what exactly am I doing wrong here?
Update: Heres some of the php code I'm using to retrieve the value.
//gets the namespace from the model $xpathNamespace = getXpathNamespace($domxml); $xml = simplexml_load_string($domxml->saveXML()); $xml->registerXPathNamespace("n", $xpathNamespace); print_r($xml->xpath('/n:module/n:prefix/@n:value'));