Learn
parsing XML using PHP
You can
parse XML data from an XML file using PHP if you use a parser. In using
the parser you should know how to handle the starting tags that are
found in the XML file and ways to handle the ending tags in the XML
file. It is better to create functions to handle both of these.
_______________________________________________
_______________________________________________
Create
separate functions to handle the starting tags and the ending tags.
Also write a function that will handle the data that is encountered
between the starting and the ending tags. If you can do this then it
is easy to work with the parser using PHP.
While writing
the actual code you have to use xml_parser_create(); to create a parser.
You can create xml_set_element_handler(); to handle the starting and
the end tags. The 'xml_set_character_data_handler();' can be used to
handle the character data that is found between the tags. You have to
set the handlers first and then open the XML file to read and parse.
Once this task is over you should not forget to free up the memory taken
by the parser and then close the XML used.
Linked by Thom Holwerda on Wed 13th Jul 2005 17:02 UTC (New Mobile Computing)
This tutorial is part I of a three-part series ( part II | part III ) that takes you from the most basic PHP script to working with databases and streaming from the file system by documenting the building of a document workflow system.