Jump to content

Recommended Posts


This is the code that activates and calls the parser:

[code]$xmlFile = fopen($xmlFileName,'r');
xml_set_character_data_handler($reader,"char");
xml_set_element_handler($reader,"AODFindBeg","charEnd");
xml_parser_set_option($reader, XML_OPTION_CASE_FOLDING, false);


while ($data=fread($xmlFile,4096)){
xml_parse($reader,$data,feof($xmlFile)) or die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($reader)),
xml_get_current_line_number($reader)));
}

xml_parser_free($reader);
[/code]

These are the parser functions I use

[code]//Begining tag handler
function AODFindBeg($reader,$eleName,$attrib){
if((strtolower($eleName)=='results')) xml_set_character_data_handler($reader,"ReportResult");
else if((strtolower($eleName)=='date')) xml_set_character_data_handler($reader,"ReportDate");
else if((strtolower($eleName)=='name')) xml_set_character_data_handler($reader,"ReportName");
else if((strtolower($eleName)=='note_id')) xml_set_character_data_handler($reader,"ReportNoteID");
else if((strtolower($eleName)=='universal_id')) xml_set_character_data_handler($reader,"ReportUniversalID");
else if((strtolower($eleName)=='language')) xml_set_character_data_handler($reader,"ReportLanguage");

//End tag handler
function charEnd($reader,$eleName){
if((strtolower($eleName)=='report')) echo "</TR>\n";
else if((strtolower($eleName)=='database')) echo "</TABLE>\n";

}

// Element handlers
function ReportResult($reader,$data){ echo "<TD>$data</TD>\n"; }
function ReportDate($reader,$data){ echo "<TD>$data</TD>\n"; }
function ReportName($reader,$data){ echo "<TD>$data</TD>\n"; }
function ReportNoteID($reader,$data){ echo "<TD>$data</TD>\n"; }
function ReportUniversalID($reader,$data){ echo "<TD>$data</TD>\n"; }
function ReportLanguage($reader,$data){ echo "<TD>$data</TD>\n"; }
[/code]

Now, my problem is that for every begin and end element, I get an extra TD /TD in my table rows. It seems that the parser puts out $data=chr(13).chr(10)."          " at each begin and/or end. Can anyone tell me how to prevent this from happening?
Link to comment
https://forums.phpfreaks.com/topic/27622-xml-parser-adds-extra-elements/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.