Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 665215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:41:06+00:00 2026-05-13T23:41:06+00:00

I am using the DOM extension to parse an xml file containing xml namespaces

  • 0

I am using the DOM extension to parse an xml file containing xml namespaces. I would have thought that namespace declarations are treated just like any other attribute, but my tests seem to disagree. I have a document that starts like this:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://purl.org/rss/1.0/"
    xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:prism="http://purl.org/rss/1.0/modules/prism/"
    xmlns:admin="http://webns.net/mvcb/"
    >

And a test code like this:

$doc = new DOMDocument();
$doc->loadXml(file_get_contents('/home/soulmerge/tmp/rss1.0/recent.xml'));
$root = $doc->documentElement;
var_dump($root->tagName);
# prints 'string(7) "rdf:RDF"'
var_dump($root->attributes->item(0));
# prints 'NULL'
var_dump($root->getAttributeNode('xmlns'));
# prints 'object(DOMNameSpaceNode)#3 (0) {}'

So the questions are:

  1. Does anyone know where could I find the documentation of DOMNameSpaceNode? A search on php.net does not yield any useful result.
  2. How do I extract all those namespace declarations from that DOMElement?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:41:07+00:00Added an answer on May 13, 2026 at 11:41 pm

    Unless there is a more direct way you can use XPath and its namespace axis.
    e.g.

    <?php
    $doc = new DOMDocument;
    $doc->loadxml('<rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns="http://purl.org/rss/1.0/"
        xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:prism="http://purl.org/rss/1.0/modules/prism/"
        xmlns:admin="http://webns.net/mvcb/"
        >
    ...
    </rdf:RDF>');
    $context = $doc->documentElement;
    
    $xpath = new DOMXPath($doc);
    foreach( $xpath->query('namespace::*', $context) as $node ) {
      echo $node->nodeValue, "\n";
    }
    

    prints

    http://www.w3.org/XML/1998/namespace
    http://webns.net/mvcb/
    http://purl.org/rss/1.0/modules/prism/
    http://purl.org/rss/1.0/modules/syndication/
    http://purl.org/dc/elements/1.1/
    http://purl.org/rss/1.0/modules/taxonomy/
    http://purl.org/rss/1.0/
    http://www.w3.org/1999/02/22-rdf-syntax-ns#
    

    edit and btw: I haven’t found documentation for DOMNameSpaceNode either. But you can “deduct” (parts of) its functionality from the source code in ext/dom/php_dom.c
    It doesn’t seem to expose any methods and exposes the properties

    "nodeName", "nodeValue", "nodeType",
    "prefix", "localName", "namespaceURI",
    "ownerDocument", "parentNode"
    

    all handled by the same functions as the corresponding DOMNode properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You mean that you want to find the original filename… May 16, 2026 at 1:51 pm
  • Editorial Team
    Editorial Team added an answer window.open("http://www.google.com", "name_your_window", "location=1,status=1,scrollbars=1,resizable=no,width=200,height=200,menubar=no,toolbar=no"); For a list of the parameters available,… May 16, 2026 at 1:51 pm
  • Editorial Team
    Editorial Team added an answer Just had the same problem. I managed to put editor… May 16, 2026 at 1:51 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a file, which is in XML format (consists just of root start
I have created an extension for mediawiki that works in all major browsers other
I'm using the DOM extension in PHP to build some HTML documents, and I
I'm working on some PHP to create XML from a database using the DOM
I'm transforming a DOM document to XML in java using javax.xml APIs. The result
I just wanna know using org.eclipse.jdt.core.dom.ASTParser if it is possible to parse only a
Everyone knows that we should always use DOM techniques instead of regexes to extract
Having a problem while passing messages using content scripts in Google chrome extension dev
I'm using simpleXML to add in a child node within one of my XML
I have debugged through JavaScript using Firebug more than hundred times without worrying about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.