Page 1 of 1

Problem with loading into a DOM object

Posted: Fri Apr 20, 2007 8:50 am
by Pesho
Hi all,

I'm trying to load a xml content string into a DOM object, using PHP5.
the string could be found here: http://ir.ub.rug.nl/oai/?verb=ListRecor ... fix=oai_dc

my code is the following:

Code: Select all

$dom = new DomDocument();
$dom->loadXML($xml_content);
print $dom->save('newfile.xml');
The output file contains only one line - "<?xml version="1.0"?>"
Here are the warnings I receive:

Code:

Code: Select all

Warning: DOMDocument::loadXML() [function.loadXML]: XML declaration allowed only at the start of the document in Entity, line: 1 in C:\PHP\www\GuidedResearchProject\formatConversion.php on line 41

Warning: DOMDocument::loadXML() [function.loadXML]: XML declaration allowed only at the start of the document in Entity, line: 1387 in C:\PHP\www\GuidedResearchProject\formatConversion.php on line 41

Warning: DOMDocument::loadXML() [function.loadXML]: XML declaration allowed only at the start of the document in Entity, line: 2887 in C:\PHP\www\GuidedResearchProject\formatConversion.php on line 41

Warning: DOMDocument::loadXML() [function.loadXML]: XML declaration allowed only at the start of the document in Entity, line: 4325 in C:\PHP\www\GuidedResearchProject\formatConversion.php on line 41
22

Posted: Fri Apr 20, 2007 9:06 am
by Kieran Huggins
sounds like you have multiple occurances of "<?xml version="1.0"?>" in your $xml_content

Posted: Fri Apr 20, 2007 9:50 am
by guitarlvr
newbie question but what is DOM?

Wayne

Posted: Fri Apr 20, 2007 10:01 am
by Pesho
thanks, Kieran,
indeed this is the problem. It's a little strange, because the repository I'm getting the xml from doesn't contain such tgags. Obviously PHP adds them in some strange manner. hmmm...

and Wayne, DOM is short for Document Object Model - a model representation of XML files....


Pesho

Posted: Fri Apr 20, 2007 10:03 am
by guitarlvr
Thanks. I'll have to do some research on it.

Wayne

Posted: Fri Apr 20, 2007 2:21 pm
by volka

Code: Select all

$xml_content = file_get_contents('http://ir.ub.rug.nl/oai/?verb=ListRecords&metadataPrefix=oai_dc');

$dom = new DomDocument();
$dom->loadXML($xml_content);
print $dom->save('newfile.xml');
works fine for me, no errors, no warnings.