|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-03-07 21:12 UTC] goetas at lignano dot it
Description:
------------
If a XML file is not well formatted, exmample:
<div t:attr="test">foo</div>
(lacks the namespace declaration for "t" namespace)
The DOM extension works differently on windows and also some version of ubuntu all running php 5.5.10 or 5.3.28
DOMDocument::loadXML always return true (with a warning, on all OS)
but DOMDocument::saveXML return different output on different OS
Windows:
DOM/XML API Version:20031129, libxml: 2.9.0
Linux:
DOM/XML API Version20031129, libxml: 2.7.6
Test script:
---------------
$a = new DOMDocument('1.0', 'UTF-8');
var_dump($a->loadXML('<div x:attr="test">foo</div>')); // returns true
echo $a->saveXML();
Expected result:
----------------
<br />
<b>Warning</b>: DOMDocument::loadXML(): Namespace prefix x for attr on div is not defined in Entity, line: 1 in <b>[...][...]</b> on line <b>2</b><br />
bool(true) <<-- i do not know if it should be true or not
<?xml version="1.0"?>
<div t:attr="test">foo</div>
(xml looks good, all nodes preserved)
Actual result:
--------------
<br />
<b>Warning</b>: DOMDocument::loadXML(): Namespace prefix x for attr on div is not defined in Entity, line: 1 in <b>[...][...]</b> on line <b>2</b><br />
bool(true)
<?xml version="1.0"?>
<div attr="test">foo</div>
(t: prefix removed)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 23:00:01 2025 UTC |
I agree with you, that is an libxml issue, But sounds strange that: // NOT valid XML laodXML('...') // return false // Valid XML laodXML('<div/>') // return true // NOT Valid XML laodXML('<t:div/>') // return true but should be false I do non know about libxml internals, but if it raises a warning, can it be used to sets to 'false' the "laodXML" return value?