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