Results 1 to 3 of 3

Thread: Validating XML in PHP (error on one server but not on the other)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Validating XML in PHP (error on one server but not on the other)

    Hi All,

    I have read a good online tutorial by Brian M. Carey. The tutorial teaches how to validate an XML file in PHP. The problem I am having now is, when I run the PHP code on MAMP server on my Mac everything works fine. It gives the output 'invalid' just one word on the screen (because of integer, seven and 7), which is what is expected of the code. But when I run the same PHP code on XAMPP server on my PC, I get some Warning messages.

    I have checked that line 7, and everything is fine. But why am I getting this warning? Has this got something to do with the configuration of my XAMPP server? Recently, I tried another piece of PHP code on two different computers running XAMPP, the same code worked well on one while it gave warnings on the other.

    I had wasted many hours trying to figure out what was wrong with this code before moving it to MAMP for testing.

    However, my question here is for this particular problem with XML validation. The work has three files (xsd, xml, php) and they are below.

    Code:
    1)The lures.xsd file:
    
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="lures">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="lure">
        <xs:complexType>
        <xs:sequence>
        <xs:element name="lureName" type="xs:string"/>
        <xs:element name="lureCompany" type="xs:string"/>
        <xs:element name="lureQuantity" type="xs:integer"/>
        </xs:sequence>
       </xs:complexType>
      </xs:element>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
    </xs:schema>
    Code:
    2)The lures.xml file:
    
    <lures>
     <lure>
      <lureName>Silver Spoon</lureName>
      <lureCompany>Clark</lureCompany>
      <lureQuantity>Seven</lureQuantity>
     </lure>
    </lures>
    Code:
    3)The testxml.php code:
    <?php
     
    $xml = new DOMDocument();
    $xml->load('./lures.xml');
    
    if (!$xml->schemaValidate('./lures.xsd')) {
        echo "invalid</p>";
      }
    
      else {
             echo "validated</p>";
      }
    
    ?>
    And the warning message from XAMPP server is below.
    Code:
    Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: I/O warning : failed to load external entity "file:///C:/xampp/htdocs/menre/MYIBM/lures.xsd" in C:\xampp\htdocs\menre\MYIBM\testxml.php on line 7
    
    Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: Failed to locate the main schema resource at 'C:\xampp\htdocs\menre\MYIBM\lures.xsd'. in C:\xampp\htdocs\menre\MYIBM\testxml.php on line 7
    
    Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: Invalid Schema in C:\xampp\htdocs\menre\MYIBM\testxml.php on line 7
    invalid
    Can anyone help please?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Validating XML in PHP (error on one server but not on the other)

    well, it's having trouble finding "lures.xsd" in the directory C:\xampp\htdocs\menre\MYIBM\. are you absolutely, positively sure that it exists? try using an absolute path instead.

    that's all this really says.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Resolved Re: Validating XML in PHP (error on one server but not on the other)

    Hello,

    Thanks for your response. The file lures.xsd really existed in that directory. I tried it now with the absolute path and it worked fine.

    Once again, thanks.

Posting Permissions

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



Click Here to Expand Forum to Full Width