Just want to make sure if this is how you validate XML. By that I mean checking for errors. Being able to see if it's correctly structured:
Given the following XML data:
$x = '<fruits>
<fruit>
<type>apple</type>
<color>red</color>
</fruit>
<fruit>
<type>lemon</type>
<color>green</color>
</fruit>
</fruits>';
This is how I'm validating it:
$success = xml_parse($parser, $x);
if($success == 0) {
$error_code = xml_get_error_code($parser);
echo "error: ".xml_error_string($error_code)."<BR>";
echo "row number: ".xml_get_current_line_number($parser)."<BR>";
echo "column number: ".xml_get_current_column_number($parser)."<BR>";
}
else { // validated, now display values
foreach($fruits as $value){
echo $value['type']."|".$value['color']."<br>";
}
}
Just want to make sure if this is how you validate it. Thanks