Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 25th, 2013  |  syntax: None  |  size: 1.92 KB  |  views: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <rdf:RDF
  2.     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  3.     xmlns="http://purl.org/rss/1.0/"
  4.     xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
  5.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  6.     xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
  7.     xmlns:prism="http://purl.org/rss/1.0/modules/prism/"
  8.     xmlns:admin="http://webns.net/mvcb/"
  9.     >
  10.        
  11. $doc = new DOMDocument();
  12. $doc->loadXml(file_get_contents('/home/soulmerge/tmp/rss1.0/recent.xml'));
  13. $root = $doc->documentElement;
  14. var_dump($root->tagName);
  15. # prints 'string(7) "rdf:RDF"'
  16. var_dump($root->attributes->item(0));
  17. # prints 'NULL'
  18. var_dump($root->getAttributeNode('xmlns'));
  19. # prints 'object(DOMNameSpaceNode)#3 (0) {}'
  20.        
  21. <?php
  22. $doc = new DOMDocument;
  23. $doc->loadxml('<rdf:RDF
  24.     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  25.     xmlns="http://purl.org/rss/1.0/"
  26.     xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
  27.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  28.     xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
  29.     xmlns:prism="http://purl.org/rss/1.0/modules/prism/"
  30.     xmlns:admin="http://webns.net/mvcb/"
  31.     >
  32. ...
  33. </rdf:RDF>');
  34. $context = $doc->documentElement;
  35.  
  36. $xpath = new DOMXPath($doc);
  37. foreach( $xpath->query('namespace::*', $context) as $node ) {
  38.   echo $node->nodeValue, "n";
  39. }
  40.        
  41. http://www.w3.org/XML/1998/namespace
  42. http://webns.net/mvcb/
  43. http://purl.org/rss/1.0/modules/prism/
  44. http://purl.org/rss/1.0/modules/syndication/
  45. http://purl.org/dc/elements/1.1/
  46. http://purl.org/rss/1.0/modules/taxonomy/
  47. http://purl.org/rss/1.0/
  48. http://www.w3.org/1999/02/22-rdf-syntax-ns#
  49.        
  50. "nodeName", "nodeValue", "nodeType",
  51. "prefix", "localName", "namespaceURI",
  52. "ownerDocument", "parentNode"
  53.        
  54. echo $root->getAttributeNode('xmlns')->nodeValue . "n";
  55. echo $root->getAttribute('xmlns') . "n";
  56. echo $root->getAttribute('xmlns:syn') . "n";
  57.        
  58. http://purl.org/rss/1.0/
  59. http://purl.org/rss/1.0/
  60. http://purl.org/rss/1.0/modules/syndication/
clone this paste RAW Paste Data