Validating XML String using PHP

With XML in a string, call DOMDocument::schemaValidateSource() or DOMDocument::relaxNGValidateSource():

$xml = '<person><firstname>Raja</firstname></person>';
$schema = 'address.xsd';
$ab = new DOMDocument
$ab->load($file);
 
if ($ab->&gt;schemaValidateSource($schema)) {
    print "XML is valid.\n";
} else {
    print "XML is invalid.\n";
}

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Filed Under: PHP XML Examples

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.