With domit! Do simple XML processing work _php Tutorial

Source: Internet
Author: User
Once I got a job dealing with XML files. This XML file is used to communicate with the Flash MP3 player, including the address, description, etc. of the music. All I need to do is get the administrator to complete adding, deleting music items and updating the XML file through a single form. Sounds easy, doesn't it? But I was having trouble deleting the function. When I spent countless hours scratching finding, searching, and flipping through the contents of DOM XML in the official PHP document, domit! Appeared in time (in fact, I found it in time). domit! Very powerful, easy-to-use (at least for simple processing), compatible with PHP4, and helps you learn DOM XML quickly when you are willing to read its source code carefully.

The XML file needed at that time was in the following format:

 <xmlversion="1.0"?> 
>
<> > <> < b="">
<> > <> < b=""> Music file Location>
<> > <> < b=""> Music file title>
< b id= "Bw6l13" > > b> music recording information >
>
>

Of course, this XML file was given in advance when I took the job. But I want to use domit!. Create such a file as the first part of this series, but also to show domit! Powerful and easy to use.

The first thing we need to do is call domit!. Library file (here, download, unzip domit! Library and put all the files in the same directory as the program file you will create below) and create a domit! Document instance:

< b id= "Bw6l13" > require_once   ( xml_domit_include.php   ;  
$xmlDoc =& new Domit_ Document ) //document instance

Note that the "&" symbol is intended to be compatible with PHP4.

So we're ready to have an instance that can be used on demand. Do you see the first line in the contents of the XML file? Yes, we're going to add the XML file declaration:

$xmlDecl=&$xmlDoc -createprocessinginstruction(XML,version= "1.0");
$xmlDoc -appendchild($xmlDecl);

In this we can see that the declaration information is also treated as a child node, which is also considered a reasonable definition. But here we can see that there is an obvious drawback to the createprocessinginstruction () approach--only two declaration parameters (usually we may also define XML declaration information such as encoding). Fortunately we are using an open source library, which means that we can easily modify it to meet the requirements. If you really need help modifying this particular method to add enough XML file declaration information (such as encoding, etc.), I'll cover it in the last article in this series.

< b id= "bw6l15" > Let's get back to the chase. After completing the XML File Declaration section, we see the "audio" tag in the XML file content. It is the root element in this XML file (the root node). Let's create this section:

 $rootElement  =&   $xmlDoc  ->  createelement   ( audio  "  ;  
$xmlDoc -> appendchild ( $rootElement " ;

< b id= "bw6l15" > You don't have to worry about the label off, domit! is completely ready for you. Using a similar approach, we will build the "audio" sub-node-"file" element, and within the "file" element, also contains several sister elements "track", "caption" and "record" and their textual content. Since they are created with a primary method AppendChild (), we can generalize to a

http://www.bkjia.com/PHPjc/486494.html www.bkjia.com true http://www.bkjia.com/PHPjc/486494.html techarticle once I got a job dealing with XML files. This XML file is used to communicate with the Flash MP3 player, including the address, description, etc. of the music. What I need to do is just ...

  • 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.