Bug #54072 [Com]: simplexml_load_file wont load the xml from LOC which has a ':'
| From: | cmbecker69 at gmx dot de | Date: | Mon, 10 Nov 2014 18:50:50 +0000 |
| Subject: | Bug #54072 [Com]: simplexml_load_file wont load the xml from LOC which has a ':' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188540@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54072&edit=1
ID: 54072
Comment by: cmbecker69 at gmx dot de
Reported by: sdowney717 at gmail dot com
Summary: simplexml_load_file wont load the xml from LOC which
has a ':'
Status: Open
Type: Bug
Package: XML related
Operating System: Ubuntu
PHP Version: 5.3SVN-2011-02-22 (SVN)
Block user comment: N
Private report: N
New Comment:
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;
Previous Comments:
------------------------------------------------------------------------
[2011-02-22 17:29:21] 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 ( [@attr!
ibutes] => 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 ( [t!
ag] => 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54072&edit=1