Re: [PHP] DOM API Namespaces - help?
Cheers indeed Rob! That DOMXPath solution is exactly what I was looking for; Many, Many Thanks, Nathan Rob wrote: Hi Nathan, Nathan Rixham wrote: Cheers Rob, But this is the problem, I don't know what the namespace/prefix is! ie "xi" and the following doesn't work: $root->getAttributeNS('http://www.w3.org/2000/xmlns/', '*'); further xmlns is ?not? a prefix so this won't work either.. $root->lookupPrefix('http://www.w3.org/2000/xmlns/'); we need to assume that we don't know the document we're working on, thus we don't know: a] if it has any namespaces defined b] if any, what the namespaces are c] if any, what the prefixes are. And I still can't find any way of finding this out, it should be simple enough surely? still help!? There are a couple of ways to do this. Using only DOM, you can grab the namespaces via XPath: $root = $dom->documentElement; $xpath = new DOMXPath($dom); $nodes = $xpath->query('namespace::*'); foreach ($nodes AS $node) { print "x: ".$node->localName."\n"; } A simpler solution is to use simplexml: $sxe = simplexml_import_dom($root); var_dump($sxe->getDocNamespaces(true)); Rob Nathan Rob wrote: Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Hi Nathan, Nathan Rixham wrote: Cheers Rob, But this is the problem, I don't know what the namespace/prefix is! ie "xi" and the following doesn't work: $root->getAttributeNS('http://www.w3.org/2000/xmlns/', '*'); further xmlns is ?not? a prefix so this won't work either.. $root->lookupPrefix('http://www.w3.org/2000/xmlns/'); we need to assume that we don't know the document we're working on, thus we don't know: a] if it has any namespaces defined b] if any, what the namespaces are c] if any, what the prefixes are. And I still can't find any way of finding this out, it should be simple enough surely? still help!? There are a couple of ways to do this. Using only DOM, you can grab the namespaces via XPath: $root = $dom->documentElement; $xpath = new DOMXPath($dom); $nodes = $xpath->query('namespace::*'); foreach ($nodes AS $node) { print "x: ".$node->localName."\n"; } A simpler solution is to use simplexml: $sxe = simplexml_import_dom($root); var_dump($sxe->getDocNamespaces(true)); Rob Nathan Rob wrote: Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Cheers Rob, But this is the problem, I don't know what the namespace/prefix is! ie "xi" and the following doesn't work: $root->getAttributeNS('http://www.w3.org/2000/xmlns/', '*'); further xmlns is ?not? a prefix so this won't work either.. $root->lookupPrefix('http://www.w3.org/2000/xmlns/'); we need to assume that we don't know the document we're working on, thus we don't know: a] if it has any namespaces defined b] if any, what the namespaces are c] if any, what the prefixes are. And I still can't find any way of finding this out, it should be simple enough surely? still help!? Nathan Rob wrote: Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Nathan Rixham wrote: > but assuming the above file is: > > http://www.w3.org/2001/XInclude";> > > > > how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] DOM API Namespaces - help?
Help?? I need to get the namespaces from the root node of a DomDocument.. http://www.w3.org/2001/XInclude";> I know I can retrieve the namespaceUri from the "xi:include" node using lookupNamespaceURI and ->prefix but I need to get it from where it's defined in "chapter" but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; Thanks in advance! Nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php