php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55317 SimpleXML loses DTD declaration on simplexml_load_file
Submitted: 2011-07-29 11:44 UTC Modified: 2016-09-11 04:22 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: schalk at unf dot edu Assigned: cmb (profile)
Status: No Feedback Package: SimpleXML related
PHP Version: 5.3.6 OS: OSX 10.6.8
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: schalk at unf dot edu
New email:
PHP Version: OS:

 

 [2011-07-29 11:44 UTC] schalk at unf dot edu
Description:
------------
I guess this may not be a bug but I can find no information about how to import an XML with a DTD declaration (<!DOCTYPE...) and have the resulting XML still contain the declaration when I use the asXML method.  All I get is the file with the declaration removed.  I have tried LIBXML_DTDLOAD, LIBXML_DTDATTR and they don't seem to help.

On a related note when I set an element using simplexml and it includes an '&' ans part of an entity reference (i.e. &M;) it gets converted to '&amp;'. How can I stop that?

Test script:
---------------
$exptml= simplexml_load_file('http://chalk.coas.unf.edu/eureka/files/templates/tmpl_chm.xml');
echo $exptml->asXML();

Expected result:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<!-- Example Chemical - ExptML v0.1 SJC 4/7/11 -->
<!DOCTYPE ExptML SYSTEM "http://chalk.coas.unf.edu/eureka/files/exptml/exptml_entities.dtd">
<chemical id="pid" xmlns="urn:exptml:schema:draft:0.1"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:unitsml="urn:oasis:names:tc:unitsml:schema:xsd:UnitsMLSchema-1.0"
	xsi:schemaLocation="urn:exptml:schema:draft:0.1 http://chalk.coas.unf.edu/eureka/files/exptml/exptml_chemical.xsd" version="0.1">
<name>Chemical name</name>
...
</chemical>


Actual result:
--------------
<?xml version="1.0" encoding="UTF-8"?>
<!-- Example Chemical - ExptML v0.1 SJC 4/7/11 -->

<chemical id="pid" xmlns="urn:exptml:schema:draft:0.1"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:unitsml="urn:oasis:names:tc:unitsml:schema:xsd:UnitsMLSchema-1.0"
	xsi:schemaLocation="urn:exptml:schema:draft:0.1 http://chalk.coas.unf.edu/eureka/files/exptml/exptml_chemical.xsd" version="0.1">
<name>Chemical name</name>
...
</chemical>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-25 20:07 UTC] virtual dot greg at gmail dot com
This does not manifest in 5.3.8 on OS X 10.6.8, the '<!DOCTYPE' is not removed.

I'd post my test script and output but I keep getting the error "Please do not 
SPAM our bug system."
 [2012-02-25 20:11 UTC] virtual dot greg at gmail dot com
See my gist for test code and output: https://gist.github.com/1910382
 [2016-09-01 22:44 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-09-01 22:44 UTC] cmb@php.net
I can't reproduce this issue with current PHP-5.6. Can anybody
else?
 [2016-09-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Mar 20 22:01:27 2019 UTC