Hi Sue. If you upgrade to PHP 5.x, you'll have the SimpleXML library at your disposal. This greatly simplifies the parsing of XML documents.
For PHP4, here are a few links (sorry about the link breaks): http://www.developertutorials.com/tutorials/php/parsing-xml-using-php4-050816/page1.html http://www.devshed.com/c/a/XML/Using-PHP-with-XML-part-1/ http://www.devshed.com/c/a/XML/Using-PHP-with-XML-part-2/ For PHP5: http://www.devshed.com/c/a/PHP/Introducing-SimpleXML-in-PHP-5/ Hope these help, ~Caitlin --- sjmagain <[EMAIL PROTECTED]> wrote: > I'm trying to figure out how to parse very simple XML files using PHP > > 4.3. I have been unsuccessful at finding simple explanations of how > to do this. > > I found the following code somewhere (can't remember where) and it > works great EXCEPT it does not keep my CSS class tags. The result is > that everything shows up as a <p> rather than <p class="text">, etc. > How do I modify this code to allow this? Or is there a better way to > accomplish this? > > TIA > > Sue > > <?php > $file = "myfile.xml"; > $map_array = array( > "bold" => "b", > "emphasis" => "i", > "literal" => "tt" > ); > > function startElement($parser, $name, $attrs) > { > global $map_array; > if (isset($map_array[$name])) { > echo "<$map_array[$name]>"; > } > } > > function endElement($parser, $name) > { > global $map_array; > if (isset($map_array[$name])) { > echo "</$map_array[$name]>"; > } > } > > function characterData($parser, $data) > { > echo $data; > } > > $xml_parser = xml_parser_create(); > // use case-folding so we are sure to find the tag in $map_array > xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); > xml_set_element_handler($xml_parser, "startElement", "endElement"); > xml_set_character_data_handler($xml_parser, "characterData"); > if (!($fp = fopen($file, "r"))) { > die("could not open XML input"); > } > > while ($data = fread($fp, 4096)) { > if (!xml_parse($xml_parser, $data, feof($fp))) { > die(sprintf("XML error: %s at line %d", > xml_error_string(xml_get_error_code($xml_parser)), > xml_get_current_line_number($xml_parser))); > } > } > xml_parser_free($xml_parser); > ?> > > > > > > Community email addresses: > Post message: [email protected] > Subscribe: [EMAIL PROTECTED] > Unsubscribe: [EMAIL PROTECTED] > List owner: [EMAIL PROTECTED] > > Shortcut URL to this page: > http://groups.yahoo.com/group/php-list > Yahoo! Groups Links > > > > > "Be who you are and say what you feel because those who mind don't matter and those who matter don't mind." - Dr. Seuss, "Oh the Places You'll Go" __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com Community email addresses: Post message: [email protected] Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-list/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/php-list/join (Yahoo! ID required) <*> To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
