Problem with loading into a DOM object

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pesho
Forum Newbie
Posts: 12
Joined: Fri Jan 27, 2006 9:43 am

Problem with loading into a DOM object

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

sounds like you have multiple occurances of "<?xml version="1.0"?>" in your $xml_content
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

newbie question but what is DOM?

Wayne
Pesho
Forum Newbie
Posts: 12
Joined: Fri Jan 27, 2006 9:43 am

Post 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
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

Thanks. I'll have to do some research on it.

Wayne
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Post Reply