|
-
Nov 14th, 2009, 05:38 AM
#1
Thread Starter
Addicted Member
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
-
Nov 14th, 2009, 11:24 AM
#2
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.
-
Nov 16th, 2009, 04:52 AM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|