user151841
user151841

Reputation: 18046

Can't return namespace from SimpleXML

I am creating a new xml document from scratch using a google defined format and SimpleXML. I'm having problems getting it to return namespaced tags. To test, I wrote this:

<?php

  $output_xml = new SimpleXMLElement('<?xml version="1.0" ?> <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"><channel></channel></rss>');

  var_dump($output_xml->getNameSpaces(TRUE));

which returns this:

array(0) {
}

What am I doing wrong? I'm running PHP version 5.3.3.

Upvotes: 0

Views: 196

Answers (1)

Samuel Cook
Samuel Cook

Reputation: 16828

you haven't used any of the namespaces defined. if you add your "g" namespace to "channel" then you will get http://base.google.com/ns/1.0

$output_xml = new SimpleXMLElement('<?xml version="1.0" ?> <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"><g:channel></g:channel></rss>');

var_dump($output_xml->getNameSpaces(TRUE));

Upvotes: 1

Related Questions