Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

php simple XML parser

Sun Oct 26, 2008 6:47 pm

Code:
<?php
$file
= "contact.xml";
   
function
startElement($parser, $name, $attrs) {
    print
"<B>$name =></B>  ";
}

function
endElement($parser, $name) {
    print
"\n";
}
   
function
characterData($parser, $value) {
    print
"$value<BR>";
}
   
$simpleparser = xml_parser_create();
xml_set_element_handler($simpleparser, "startElement", "endElement");
xml_set_character_data_handler($simpleparser, "characterData");
   
if (!(
$fp = fopen($file, "r"))) {
  die(
"could not open XML input");
}
   
while(
$data = fread($fp, filesize($file))) {
  if (!
xml_parse($simpleparser, $data, feof($fp))) {
     die(
xml_error_string(xml_get_error_code($simpleparser)));
  }
}

xml_parser_free($simpleparser);
?>

Code:
<!--
<contact id="43956">
     <personal>
          <name>
               <first>J</first>
               <middle>J</middle>
               <last>J</last>
          </name>
          <title>Manager</title>
          <employer>National Company</employer>
          <dob>1951-02-02</dob>
     </personal>
</contact>

-->




Post a reply
  Related Posts  to : php simple XML parser
 php SAX parser in action     -  
 Command Line Parser Code Using C++     -  
 How to implement Command Line Parser in C++ Code     -  
 OpenGl simple example     -  
 Simple animation     -  
 Simple Light     -  
 Simple Calculator     -  
 simple example for fixed image     -  
 lesson2 : XSD simple element     -  
 Simple Snake Game     -