By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Xml, Xschema and php

P: n/a
Someone could tell me how can I validate
an xml file against an Xschema using php?

Thanks and sorry for my little english.

-------------------------------------
"Computer Science is no more about
computers than astronomy is about
telescopes."
::[E. W. Dijkstra]
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Xaradas wrote:
Someone could tell me how can I validate
an xml file against an Xschema using php?

Thanks and sorry for my little english.

-------------------------------------
"Computer Science is no more about
computers than astronomy is about
telescopes."
::[E. W. Dijkstra]


none of the XML parsing extensions in php (SAX or DOM) do schema/dtd
validation.

Fortunately, this is not a hard limit due to the fact that you can use
other parsers via one of PHP's interfaces to external programs.

You have 3 options in that regard (external validating parsers)
1) use a command-line parser to do the job
2) load an XML parsing java class that supports validation
3) if using windows, load MSXML

For option 1, go see the PHP manual on how to execute external commands.
For option two, you should be able to find some devent parsers at
xml.apache.org. Using java from within PHP is trivial!
For option 3, I ripped this example from the user-contributed notes in
the DOM XML part of the online PHP manual.

krator at krator dot com (05-Nov-2002 01:51)

If you are using php on windows then install MSXML Core Services and use
their tools. This can be done by using the php COM functions.
<?php
$xmlparser = new COM("Microsoft.XMLDOM") or die("Unable to instanciate
MSXML");
echo "Loaded MSXML.\n";
$xmlparser->async="false";
$xmlparser->validateOnParse="true";
$xmlparser->load("d:\\xmldata\\test.xml");
echo "Error Code: ";
echo $xmlparser->parseError->errorCode;
echo "Error Reason: ";
echo $xmlparser->parseError->reason;
echo "Error Line: ";
echo $xmlparser->parseError->line;
?>
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.