php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41405 asXML() does not return the whole xml
Submitted: 2007-05-16 02:00 UTC Modified: 2007-05-18 01:21 UTC
From: longrennet at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.2 OS: Linux ES3
Private report: No CVE-ID: None
 [2007-05-16 02:00 UTC] longrennet at hotmail dot com
Description:
------------
I'd like to print the xml string in my code, so i use function asXML(). But it just return the element value in the xml. 

Is the code before i use asXML effort it?

Reproduce code:
---------------
<?php

..........
..........
..........//Here is some code. If there is no these codes,it will be OK.


$string = <<<XML
<a>
 <b>
  <c>text</c>
  <c>stuff</c>
 </b>
 <d>
  <c>code</c>
 </d>
</a>
XML;

$xml = new SimpleXMLElement($string);

echo $xml->asXML();
?> 

Expected result:
----------------
<?xml version="1.0" ?><a><b><c>text</c><c>stuff</c></b><d><c>code</c></d></a>

Actual result:
--------------
text stuff code

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-16 11:50 UTC] rrichards@php.net
Works fine. Try viewing the actual output and not what you see in the browser.
 [2007-05-17 01:21 UTC] longrennet at hotmail dot com
SimpleXMLElement->asXML() is described as follow:

SimpleXMLElement->asXML() --  Return a well-formed XML string based on SimpleXML element.

But here just return the values of nodes, not a well-formed XML. And it will return nothing, if each node has no value. I need to the well-formed XML string, but these values.
 [2007-05-17 09:39 UTC] rrichards@php.net
It does return well formed XML.
I repeat - You cannot see it correctly in your browser
the browser doesn't display the element tags
Try your code under CLI or escape the output with htmlentities()
 [2007-05-18 01:21 UTC] longrennet at hotmail dot com
Thanks for Ur help
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 06:01:35 2025 UTC