...

View Full Version : Is This How You Validate XML?



jessjenn
01-04-2004, 05:29 PM
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

jessjenn
01-04-2004, 05:51 PM
Oh by the way, do you people know off hand how I could add these characters < > ' " & inside the XML tags? I'm escaping them with their entities (&gt; &lt; etc.) and nothing. When they print out, they print out blank. Any ideas?

me'
01-04-2004, 06:14 PM
Originally posted by jessjenn
Oh by the way, do you people know off hand how I could add these characters < > ' " & inside the XML tags? I'm escaping them with their entities (&gt; &lt; etc.) and nothing. When they print out, they print out blank. Any ideas? If you've got your own DTD:
<!ELEMENT elementname (#CDATA) !>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum