Code has been added to clipboard!

Detecting XML Issues

Example
<?php
  libxml_use_internal_errors(true);
  $my_data =
    "<?xml version='1.0' encoding='UTF-8'?> 
    <document> 
    <to>You</wrong>
    <from>Me</wrong>
    <heading>The Game</wrong>
    <body>You lost it</wrong>
    </document>"; 

  $xml = simplexml_load_string($my_data);
  if ($xml === false) {
    echo "Failed to load XML: ";
    foreach(libxml_get_errors() as $error) {
      echo "<br>", $error->message;
    }
  } else {
    print_r($xml);
  }
?>