Jump to content

PHP and XML


aspnetguy

Recommended Posts

Ok so I am creating an app that uses XML to store the data. I have also created Schemas for the XML file sto follow.I have found lots of articles on how to read in the XML with PHP but how do I compare the XML I am reading and creating to the Schema to ensure it is following the rules?

Link to comment
Share on other sites

Actually the term is "check/validate against", not "compare" for obvious reasons :) .This article shows a simple function for that in PHP5.So, I think this should work as a simple errorless validator, though I haven't tested it:

<?php$dom = new DomDocument();$dom->load("test.xml");if ($dom->schemaValidate('schema.xsd') === FALSE) {echo "Invalid XML document";}else {echo "VALID XML document";}?>

Every other action that is XML realated uses other DOM functions. Be sure to check them out.

Link to comment
Share on other sites

thanks, is there a method for PHP4 or will I have to upgrade?
PHP4 has equivalent DOM XML functions but I don't think a Schema validation is among the supported objects. You'll have to upgrade.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...