Bug #66850 [Nab]: Different behaviors of loadXML

From: Date: Tue, 11 Mar 2014 14:22:20 +0000
Subject: Bug #66850 [Nab]: Different behaviors of loadXML
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184720@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66850&edit=1

 ID:                 66850
 Updated by:         ab@php.net
 Reported by:        goetas at lignano dot it
 Summary:            Different behaviors of loadXML
 Status:             Not a bug
 Type:               Bug
 Package:            DOM XML related
 Operating System:   windows/linux (ubuntu)
 PHP Version:        5.5.10
 Block user comment: N
 Private report:     N

 New Comment:

You can see the relevant code here http://lxr.php.net/xref/PHP_5_6/ext/dom/document.c#dom_document_parser
. Generally we rely on libxml, so if it could parse, that's the precondition for the DOM
extension to work further.


Previous Comments:
------------------------------------------------------------------------
[2014-03-11 12:59:51] goetas at lignano dot it

But if it is not a bug, why loadXML() returns a 'true'?

------------------------------------------------------------------------
[2014-03-11 10:06:42] ab@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

There are two points why it's not a bug:

- loading an invalid XML document (or say some HTML4) has always an unpredictable effect, especially
if there's no validation happened before

- what you mention as a difference in handling is up to the libxml version, it has nothing to do
with the OS. When different dependency libs are used, the some discrepancy is even expected.

Depending on what you do, you can always use the latest libxml by doing a custom build.

Thanks

------------------------------------------------------------------------
[2014-03-07 21:12:49] 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)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=66850&edit=1


Thread (9 messages)

« previous php.bugs (#184720) next »