php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31200 DOMDocument->xinclude() outputs a part of the DTD
Submitted: 2004-12-20 14:03 UTC Modified: 2005-03-02 20:08 UTC
From: diodu at keliglia dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.0.3 OS: Linux debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: diodu at keliglia dot com
New email:
PHP Version: OS:

 

 [2004-12-20 14:03 UTC] diodu at keliglia dot com
Description:
------------
When trying to xinclude an XML file with an attached DTD, DOMDocument->xinclude() outputs a part of the DTD in the result. Deleting the Doctype line in the included file fix the problem.

Reproduce code:
---------------
<?php
// book.xml being the XML file described here: http://livedocs.phpdoc.info/index.php?l=en&q=ref.dom#dom.examples


$xml =<<<EOD
<?xml version="1.0" ?>
<chapter xmlns:xi="http://www.w3.org/2001/XInclude">
 <title>Books of the other guy..</title>
 <para>
  <xi:include href="book.xml#xpointer(/book/chapter/para/informaltable/tgroup/tbody/*)" parse="xml">
   <xi:fallback>
    <error>xinclude: book.xml not found</error>
   </xi:fallback>
  </xi:include>
 </para>
</chapter>
EOD;

$dom = new DOMDocument;
$dom->loadXML($xml);

$dom->xinclude();

echo $dom->saveXML();

?>

Expected result:
----------------
<?xml version="1.0"?>
<chapter xmlns:xi="http://www.w3.org/2001/XInclude">
 <title>Books of the other guy..</title>
 <para>
  <row xml:base="/home/didou/book.xml">
       <entry>The Grapes of Wrath</entry>
       <entry>John Steinbeck</entry>
       <entry>en</entry>
       <entry>0140186409</entry>
      </row><row xml:base="/home/didou/book.xml">
       <entry>The Pearl</entry>
       <entry>John Steinbeck</entry>
       <entry>en</entry>
       <entry>014017737X</entry>
      </row><row xml:base="/home/didou/book.xml">
       <entry>Samarcande</entry>
       <entry>Amine Maalouf</entry>
       <entry>fr</entry>
       <entry>2253051209</entry>
      </row>
 </para>
</chapter>


Actual result:
--------------
<?xml version="1.0"?>
<!DOCTYPE chapter [
<!ENTITY uArr "?">
<!ENTITY hcirc "ĥ">
<!ENTITY icirc "î">
<!ENTITY equals "=">
<!ENTITY cong "?
">
<!ENTITY icy "О">

// a hundred of similar lines

<!ENTITY sstarf "?">
<!ENTITY samalg "?The Grapes of Wrath</entry>
       <entry>John Steinbeck</entry>
       <entry>en</entry>
       <entry>0140186409</entry>
      </row><row xml:base="/home/didou/book.xml">
       <entry>The Pearl</entry>
       <entry>John Steinbeck</entry>
       <entry>en</entry>
       <entry>014017737X</entry>
      </row><row xml:base="/home/didou/book.xml">
       <entry>Samarcande</entry>
       <entry>Amine Maalouf</entry>
       <entry>fr</entry>
       <entry>2253051209</entry>
      </row>
 </para>
</chapter>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-20 14:10 UTC] chregu@php.net
libxml2 does automatically resolve external entities, and I didn't find a way to turn that off from the php side... 

We have to investigate the issue, it's not only annoying, but also a performance bottleneck


 [2005-03-02 20:08 UTC] rrichards@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

This is libxml behavior. DTD only output - it gets created for existing Document if one doesnt exists - only if Entities are defined as they may be required for the included Document. As a workaround in PHP 5.1 you can use:
$dom->xinclude(LIBXML_NONET);

This will prevent remote files (i.e. DTD) from being loaded which will reduce performance bottleneck, but it will still load local DTDs. Note that not including the DTD may break the xml if any entity definitions are required in the resulting document.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 20:01:31 2024 UTC