Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove xml version tag when a xml is created in php

Tags:

php

xml

I'm creating a xml using this

$customXML = new SimpleXMLElement('<abc></abc>'); 

after adding some attributes onto this, when I try to print it it appears like this,

<?xml version="1.0"?> <abc id="332"><params><param name="aa">33</param></params></abc> 

Is there a way to remove the xml version node ? Thank you

like image 710
Dhiraj Avatar asked May 10 '11 09:05

Dhiraj


People also ask

How do I remove an XML tag?

If you want to remove the spaces before the tag you can use the following instead: find [\t ]*<time>[0-9A-Z:-]*</time> replace with blank. Thanks that works for me!

Which tag shows which version of XML is used?

The version=”1.0″ is the version of the XML currently used. There are various versions of XML available. The encoding= ”UTF-8″ specifies the character encoding used while writing an XML document, for example, êèé is for French and so on. Its default value is “UTF-8”.

Is <? XML required?

<? xml version="1.0" encoding="UTF-8"?>

What is XML parser PHP?

What is an XML Parser? To read and update, create and manipulate an XML document, you will need an XML parser. In PHP there are two major types of XML parsers: Tree-Based Parsers. Event-Based Parsers.


1 Answers

In theory you can provide the LIBXML_NOXMLDECL option to drop the XML declaration when saving a document, but this is only available in Libxml >= 2.6.21 (and buggy). An alternative would be to use

$customXML = new SimpleXMLElement('<abc></abc>'); $dom = dom_import_simplexml($customXML); echo $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement); 
like image 136
Gordon Avatar answered Sep 18 '22 15:09

Gordon