Adding namespace to root element #6
Replies: 5 comments
-
I have the same problem. i need to to something like this:
how can i do this? |
Beta Was this translation helpful? Give feedback.
-
I've got same trouble, any ideas? I basically need to parse xmpp xml stream. |
Beta Was this translation helpful? Give feedback.
-
Hi guys and thanks for the good questions. Sorry if this particular situations are not covered by the documentation; I will extend the doc to cover these cases too. Anyway, // We have to postpone the root creation.
$rss = fluidxml(null);
$rss->namespace('g', 'http://base.google.com/ns/1.0');
$root = $rss->addChild('rss', true);
// Accessing the node as array returns the DOMNode.
// In this case $root[0] is the first and only associated DOMNode.
$root[0]->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:g', 'http://base.google.com/ns/1.0');
// Your root has the namespace registered. Continue as usual.
$channel = $rss->addChild('channel', true);
... @eolandro your case is quite similar. $xml = fluidxml(null);
$xml->namespace('BCE', '{BCE_URI}');
$root = $xml->add('BCE:Balanza', true);
$root[0]->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:xsi', '{XSI_URI}');
$xml->attr('xsi:schemaLocation', '{SCHEMA_URI}');
// Your root has the namespace registered. Continue as usual.
$xml->addChild('BCE:Ctas', [ 'NumCta' => '100' ]);
... |
Beta Was this translation helpful? Give feedback.
-
I updated the Getting Started namespace section to reflect these cases. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to add a namespace to the root element. I'm going for this:
I'm using the following code:
which gives me:
Is it possible to have both the rss tag and the channel tag at the root level? |
Beta Was this translation helpful? Give feedback.
-
Is there a way to declare a namespace inside the documents root element?
I'd like to use it like here: https://support.google.com/merchants/answer/160589?hl=en&ref_topic=2473799
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
My code looks like this:
Beta Was this translation helpful? Give feedback.
All reactions