mpsn Posted November 10, 2011 Share Posted November 10, 2011 Hi, I get errors when trying to validate this schema. here is xml: ======== <?xml version="1.0" encoding="ISO-8859-1"?> <email> <message> <to> <toFirstName>Tove</toFirstName> <toLastName toType="common" style="swag">Smith</toLastName> </to> <from> <fromFirstName>Jani</fromFirstName> <fromLastName fromType="unique">Dravison</fromLastName> </from> <heading>Reminder</heading> <body> <prologue>Tis the night before Xmas...</prologue> </body> </message> </email> here is schema: =========== <?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="email"> <xs:complexType> <xs:element name="message"> <xs:complexType> <xs:sequence> <xs:element name="to"> <xs:complexType> <xs:sequence> <xs:element name="toFirstName" type="xs:string"/> <xs:element name="toLastName"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="from"> <xs:complexType> <xs:sequence> <xs:element name="fromFirstName" type="xs:string"/> <xs:element name="fromLastName"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="heading" type="xs:string"/> <xs:element name="body"> <xs:complexType> <xs:prologue name="prologue" type="xs:string"/> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:attribute name="toType" type="xs:string" use="required"/> <xs:attribute name="style" type="xs:string" use="required"/> <xs:attribute name="fromType" type="xs:string" use="required"/> </xs:complexType> </xs:element> </xs:schema> here is script that has validateXML function to check email.xml: ============================================ ?php //FCN SOURCE: IBM //helper FCN: that switches b/t libxml error types function showLibXMLErrors($error) { $return = "<br/>\n"; switch ($error->level) { case LIBXML_ERR_WARNING: $return .= "<b>Warning $error->code</b>: "; break; case LIBXML_ERR_ERROR: $return .= "<b>Error $error->code</b>: "; break; case LIBXML_ERR_FATAL: $return .= "<b>Fatal Error $error->code</b>: "; break; } $return .= trim($error->message); if($error->file) { $return .= " in <b>$error->file</b>"; } $return .= " on line <b>$error->line</b>\n"; return $return; } //calls showLibXMLErrors to show appropriate libxml error for line in cur XML file function validateXML() { $errors = libxml_get_errors(); foreach ($errors as $error) { print showLibXMLErrors($error); } libxml_clear_errors(); } // Enable user error handling libxml_use_internal_errors(true); $xml = new DOMDocument(); $xml->load("email.xml"); if (!$xml->schemaValidate("email.xsd")) { print '<b>Errors Found!</b>'; validateXML(); } else { print "Validated <br />"; } Please just try to run the script, just copy the info from this post and you will see errors! Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250843-xsd-validating-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.