Results 1 to 2 of 2

Thread: Problem loading XML from a file. Pls help...

  1. #1
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Problem loading XML from a file. Pls help...

    <?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/functio...ument-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!!

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Joe-W
    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 resource
    This suggests either a malformed style sheet, or malformed markup. Try validating the markup using the W3C's validator.

    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 section, along with the code shown for the XSLTProcessor constructor. If that fails for you, then you must have a problem with your configuration (PHP and libxslt versions?).

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •