PDA

View Full Version : Problem loading XML from a file. Pls help...



Joe-W
05-27-2005, 02:19 AM
<?php

header("Content-type: text/xml");

$xml = new DOMDocument;
$xml->load("input.xml");

$xsl = new DOMDocument();
$xsl->load("xsl.xsl");

// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);

echo $proc->transformToXML($xml);


Hi all, I was trying to use the above script to load a XML file
for the input.

Both the .php file and the .xml file are in the same directory,
yet it always returns a following error message:



...
Only one top level element is allowed in an XML document. Error processing resource
...

...
domdocument() expects at least 1 parameter, 0 given in... (no full path was given)

-----------

I have then tried the script from PHP.net's tutorial, just to see if it would work, but same error message... (I did make a XML file called 'book.xml' and put it in the same directory as the PHP file)

http://us2.php.net/manual/en/function.dom-domdocument-load.php


<?php
$doc = DOMDocument::load('book.xml');
echo $doc->saveXML();

$doc = new DOMDocument();
$doc->load('book.xml');
echo $doc->saveXML();
?>

-----------

Can anyone give me a hand? Thanks in advance!!

mwinter
05-29-2005, 04:38 PM
Hi all, I was trying to use the above script to load a XML file
for the input.An aside: it's better to use the code, html, or (in this case, especially) php meta tags, rather than quote, when posting code. They provide syntax highlighting and preserve formatting and indentation.


Only one top level element is allowed in an XML document. Error processing resourceThis suggests either a malformed style sheet, or malformed markup. Try validating the markup using the W3C's validator (http://validator.w3.org/).


I have then tried the script from PHP.net's tutorial, just to see if it would work, but same error message...I've successfully used the example presented in XSL functions (http://www.php.net/manual/en/ref.xsl.php) section, along with the code shown for the XSLTProcessor constructor (http://www.php.net/manual/en/function.xsl-xsltprocessor-construct.php). If that fails for you, then you must have a problem with your configuration (PHP and libxslt versions?).

Mike