xmlreader_validatedtd.php 592 B

123456789101112131415161718
  1. <?php
  2. $indent = 5; /* Number of spaces to indent per level */
  3. $xml = new XMLReader();
  4. $xml->open("dtdexample.xml");
  5. $xml->setParserProperty(XMLREADER::LOADDTD, TRUE);
  6. $xml->setParserProperty(XMLREADER::VALIDATE, TRUE);
  7. while($xml->read()) {
  8. /* Print node name indenting it based on depth and $indent var */
  9. print str_repeat(" ", $xml->depth * $indent).$xml->name."\n";
  10. if ($xml->hasAttributes) {
  11. $attCount = $xml->attributeCount;
  12. print str_repeat(" ", $xml->depth * $indent)." Number of Attributes: ".$xml->attributeCount."\n";
  13. }
  14. }
  15. print "\n\nValid:\n";
  16. var_dump($xml->isValid());
  17. ?>