|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48049 Will not parse tags with certain chars
Submitted: 2009-04-22 14:44 UTC Modified: 2010-10-22 10:28 UTC
Avg. Score:4.2 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: nickmaccarthy at gmail dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.9 OS: Ubuntu 8.04
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.
Block user comment
Status: Assign to:
Bug Type:
From: nickmaccarthy at gmail dot com
New email:
PHP Version: OS:


 [2009-04-22 14:44 UTC] nickmaccarthy at gmail dot com
Note:  SimpleXML has issues parsing tags with ":" in it.

GML tags for example are formatted like:

In the SimpleXML Documentation, it states to put tags between {} that could contain chars. that could break the parser, like "-" for example. 

In our example below:

will not be parsed by SimpleXML, but SimpleXML will NOT throw an error or lead you to believe that it has NOT parsed it.  

I was parsing output from which uses XML as an output with GML.

Here is an example of the XML I was working with when I cam a

Reproduce code:
From manual page: book.simplexml
$ipAddr = "";
$data = file_get_contents("".$ipAddr);

        $xml = @simplexml_load_string(str_replace(":", "_", $data));  //SimpleXML has issues parsing the ":", replacing it with underscore to make this work.

        $city = $xml->gml_featureMember->Hostip->gml_name;
        $country = $xml->gml_featureMember->Hostip->countryName;
        $country_abbrev = $xml->gml_featureMember->Hostip->countryAbbrev;

        $lat_long = $xml->gml_featureMember->Hostip->ipLocation->gml_PointProperty->gml_Point->gml_coordinates;

echo $city

Expected result:
This is what XML looks like coming from the site:
<HostipLookupResultSet version="1.0.0" xmlns="" xmlns:gml="" xmlns:xsi="" xsi:schemaLocation="">
 <gml:description>This is the Hostip Lookup Service</gml:description>
   <gml:name>(Unknown City?)</gml:name>
   <countryName>(Unknown Country?)</countryName>
   <!-- Co-ordinates are unavailable -->

Based on my echo of $city, I would expect to see:

Providence RI

Actual result:
Blank - nothing.  

SimpleXML will not throw an error if it runs into an issue parsing anything with a ":" in the tag.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-24 13:48 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

 [2009-05-02 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-10-22 01:17 UTC] nickmaccarthy at gmail dot com
Example Script was provided with the original request, but I will add another one.

$ipAddr = "";
$data = file_get_contents("".$ipAddr);
$xml = @simplexml_load_string($data);

You will notice that you will get no results from the print_r of $xml and there is no error message give.  This was tested again with php version 5.3.2.
 [2010-10-22 10:28 UTC]
-Status: No Feedback +Status: Bogus
 [2010-10-22 10:28 UTC]
The latest example script offered by nickmaccarthy works as expected. Nick, to see 
that the XML is received properly use:

    echo $xml->saveXML();

As for the original bug report, the reporter did not how to work with namespaces. 
This information is available in the documentation, see 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 14:01:29 2024 UTC