PHP parses Plist files in XML format

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.