php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54072 simplexml_load_file wont load the xml from LOC which has a ':'
Submitted: 2011-02-22 17:29 UTC Modified: 2014-11-10 19:01 UTC
From: sdowney717 at gmail dot com Assigned:
Status: Not a bug Package: XML related
PHP Version: 5.3SVN-2011-02-22 (SVN) OS: Ubuntu
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: sdowney717 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-02-22 17:29 UTC] sdowney717 at gmail dot com
Description:
------------
<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

$request='http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=dinosaur&startRecord=2&maximumRecords=5';
$string = file_get_contents($request);
// echo $string;
$string = str_replace(":", "_", $string);
// echo $string;

$sxe = new SimpleXMLElement($string);
if (!$sxe) {
    echo "Failed loading XML\n";
    foreach(libxml_get_errors() as $error) {
        echo "\t", $error->message;
    }
}

//var_dump  ($sxe);
print_r  ($sxe);
print $sxe[10];
?>

Test script:
---------------
<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

$request='http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=dinosaur&startRecord=2&maximumRecords=5';
$string = file_get_contents($request);
// echo $string;

$sxe = new SimpleXMLElement($string);
if (!$sxe) {
    echo "Failed loading XML\n";
    foreach(libxml_get_errors() as $error) {
        echo "\t", $error->message;
    }
}

//var_dump  ($sxe);
print_r  ($sxe);
print $sxe[10];
?>

Expected result:
----------------
Warning: SimpleXMLElement::__construct(): namespace warning : xmlns: URI http_//www.loc.gov/MARC21/slim is not absolute in /home/scott/public_html/xml5.php on line 12 Warning: SimpleXMLElement::__construct(): Array ( [xmlns_zs] => http_//www.loc.gov/zing/srw/ ) [zs_version] => 1.1 [zs_numberOfRecords] => 2144 [zs_records] => SimpleXMLElement Object ( [zs_record] => Array ( [0] => SimpleXMLElement Object ( [zs_recordSchema] => info_srw/schema/1/marcxml-v1.1 [zs_recordPacking] => xml [zs_recordData] => SimpleXMLElement Object ( [record] => SimpleXMLElement Object ( [leader] => 01026ngm a22002773a 4500 [controlfield] => Array ( [0] => 16429180 [1] => 20100823131409.0 [2] => vffcjaho| [3] => 100823s2010 xxu060 mleng ) [datafield] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 906 [ind1] => [ind2] => ) [subfield] => Array ( [0] => 0 [1] => cbc [2] => orignew [3] => u [4] => ncip [5] => 20 [6] => y-movingim ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 955 [ind1] => [ind2] => ) [subfield] => qm12 2010-08-23 ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 010 [ind1] => [ind2] => ) [subfield] => 2010608899 ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 017 [ind1] => [ind2] => ) [subfield] => Array ( [0] => PA0001684303 [1] => U.S. Copyright Office ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 040 [ind1] => [ind2] => ) [subfield] => Array ( [0] => DLC [1] => DLC [2] => amim ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 050 [ind1] => 0 [ind2] => 0 ) [subfield] => VBU 4599 (viewing copy) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 245 [ind1] => 0 [ind2] => 0 ) [subfield] => Array ( [0] => 30 Rock. [1] => Emmanuelle goes to Dinosaur Land. ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 246 [ind1] => 3 [ind2] => 0 ) [subfield] => Emmanuelle goes to Dinosaur Land ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 246 [ind1] => 3 [ind2] => ) [subfield] => Array ( [0] => Thirty rock. [1] => Emmanuelle goes to Dinosaur Land ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 257 [ind1] => [ind2] => ) [subfield] => United States. ) [10] => SimpleXMLElement Object ( [@attributes] => Array ( [tag] => 260 [ind1] => [ind2] => )

Actual result:
--------------
Nothing, simplexml does not load at all due to the ':' in the xml file



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-10 18:50 UTC] cmbecker69 at gmx dot de
This is not a bug. SimpleXML does load the document in the test
script. You can verify that by doing
  
  echo $sxe->asXML();
  
However, namespaced elements are not shown when casting a
non-namespaced SimpleXMLElement to string, and you can't access
namespaced elements directly, but you can access them via
->children() passing the desired namespace as argument:

  $zs = $sxe->children('http://www.loc.gov/zing/srw/');
  echo $zs;
 [2014-11-10 19:01 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-11-10 19:01 UTC] requinix@php.net
cmbecker69 is correct.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jan 25 11:01:23 2021 UTC