xsd validate in php

Discussion in 'PHP' started by rigas, Jan 12, 2010.

  1. #1
    hello

    using a form disigned with html i am collecting some data and saving them to an xml temp file. then i want to validate them with an xsd file in order to finally write them to save them to the ordinary file.

    using the instruction below in the xml at root element, the file opens in the browser(valid)
    <SONGS xmlns ="http://www.songs.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.songs.org p06166.xsd"
    Code (text):
    without the above instruction in the xml, i am trying to validate the xml in php with the code below
     
    $xdoc = new DomDocument;
    $xmlfile = '123.xml';
    $xmlschema = 'p06166.xsd';
     
    //Load the xml document in the DOMDocument object
    $xdoc->Load($xmlfile);
     
    //Validate the XML file against the schema
    if ($xdoc->schemaValidate($xmlschema)) {
    print "Song inserted successfully!! <br />";
    }
    else {
    print "$xmlfile is invalid.\n";
    }
    Code (text):
    the error i get is the one below. do you have any idea why i get error, since the input is valid???

    Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: Element 'SONGS': No matching global declaration available for the validation root. in C:\xampp\htdocs\test.php on line 48
     
    rigas, Jan 12, 2010 IP