During IOS development, plist files are often used. It is an XML file. This article mainly parses plist files based on the xml principle. Plist file format the plist file format parsed in this article is as follows :? Xmlversion1.0encodingUTF-8 ?! DOCTYPEplistPUBLIC-AppleComputerDTDPLIST
During IOS development, plist files are often used. It is an XML file. This article mainly parses plist files based on the xml principle. Plist file format the plist file format parsed in this article is as follows :? Xml version = "1.0" encoding = "UTF-8 "? ! DOCTYPE plist PUBLIC "-// Apple Computer // DTD PLIST
During IOS development, plist files are often used. It is an XML file. This article mainly parses plist files based on the xml principle.
Plist File Format
The plist file format parsed in this article is as follows:
KEY1
KEY_VALUE
KEY2
KEY2_key1
KEY2_key1_value1
KEY2_key2
KEY2_key2_value1
From the above format, we can get data by defining the xml parsing function.
Use php xml Parser Functions
// All variables used: global $ xml_parser, $ songs, $ number_dicts, $ current_key, $ current_element, $ current_data, $ end_of_songs; // FILE Path $ target = 'file _ path'; // FILE Name $ filename = 'file _ name'; // create an XML Parser $ xml_parser = xml_parser_create (); xml_parser_set_option ($ xml_parser, XML_OPTION_CASE_FOLDING, 1); xml_set_element_handler ($ xml_parser, "start_element", "end_element"); Aggregate ($ xml_parser, "ch Aracter_data "); if (! ($ Fp = @ fopen ($ target, "r") {return false;} while ($ data = fread ($ fp, 4096) {if (! Xml_parse ($ xml_parser, $ data, feof ($ fp) {die (sprintf ("XML error: % s at line % d in file % s \ n ", xml_error_string (xml_get_error_code ($ xml_parser), Parser ($ xml_parser), $ filename) ;}// release the specified XML Parser xml_parser_free ($ xml_parser );
The main part of the file is responsible for creating an XML Parser and defining an element processor and a character data processor.
(...)
Read the rest of PHP parsing Plist files in XML format (340 words)
©Lixiphp for LixiPHP-dedicated to advanced PHP programming !, 2013. | Permalink | No comment | Add to del. icio. us
Post tags: PHP, plist, XML
Feed enhanced by Better Feed from Ozh