remove xml version tag when a xml is created in php
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);
How to remove XML version from php://input
You could just remove it with str_replace()
:
$xmlString = file_get_contents('php://input');
$xmlString = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $xmlString);
file_put_contents("broadbeantesttest.xml", $xmlString, FILE_APPEND);
How to create XML file without XML opening tags
You could replace data in the string before to save it:
$str = $xmldata->asXML(); // get as string instead of saving file
$str = str_replace(['<?xml version="1.0"?>','<items>','</items>'],'',$str); // remove tags you don't want.
file_put_contents('xml/playlistbdays.xml', trim($str)) ; // save file
How to remove XML tag based on child attribute using php?
You need to use DOMDocument
class to parse string to XML document. Then use DOMXpath
class to find target element in document and use DOMNode::removeChild()
to remove selected element from document.
$doc = new DOMDocument();
$doc->loadXML($xml);
$xpath = new DOMXpath($doc);
// select target entry tag
$entry = $xpath->query("//entry[title[@lang='fr']]")->item(0);
// remove selected element
$entry->parentNode->removeChild($entry);
$xml = $doc->savexml();
You can check result in demo
Related Topics
How to Send a Status Code in PHP, Without Maintaining an Array of Status Names
Subquery in Doctrine2 Notin Function
Jquery Ajax Returns the Whole Page
Trim Unicode Whitespace in PHP 5.2
Can PHP and ASP.NET Run Together Within the Same Web Site in Iis 7.5
Using Nulls in a MySQLi Prepared Statement
Getting Complete Path of Uploaded File - PHP
PHP Warning: Move_Uploaded_File() Unable to Move
Split String into Sentences Using Regex
PHP Unexpected Result of Float to Int Type Cast
Remove Accents Without Using Iconv
Retrieve the Id of an Inserted Record: PHP & Ms SQL Server
How to Get the Unicode Value of a Character or Vise Versa with PHP