Unable add namespace with PHPs SimpleXML -


I am creating an Atom feed when I add xmlns: i as an attribute Tried below -

  $ node-> Add Add ("xmlns: i", "http://www.w3.org/2001/XMLSchema-instance");  

I found it as output -

  i = "http://www.w3.org/2001/XMLSchema-instance"  

"xmlns:" part was cut. I need to avoid : - character? Or is there any other way of adding this namespace?

If you want to add an attribute from the namespace / prefix i $ node Not already disturbed in declaring the namespace in the first parameter, use the third parameter of addAttribute () to provide the namespace Yuri for the prefix.

  $ node = new SimpleXMLElement ('& lt; root & gt; & lt; / root & gt;'); $ Node- & gt; Add Junk ("i: somename", "somevalue", 'http://www.w3.org/2001/XMLSchema-instance'); Echo $ node-> AsXml ();  

Print

  & lt ;? Xml version = "1.0"? & Gt; & Lt; Root xmlns: i = "http://www.w3.org/2001/XMLSchema-instance" i: somename = "somevalue" />  

If the attribute is not required, you can delete it from unset () , leaving the namespace declaration.

  unset ($ node-> Attributes ('I', true) ['Somnam']);  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -