Complete php-implemented XML operations (read) Encapsulation class instance, phpxml
This example describes the XML operation (read) Encapsulation class implemented by php. We will share this with you for your reference. The details are as follows:
<? Xml version = "1.0" encoding = "UTF-8" standalone = "no"?> <CustomizationSetting version = '1. 0'> <! -- Common configuration information, which is used as the Settings subnode for unified analysis --> <! -- AgentSettings is generated by custom web pages. By default, no secondary node exists. --> <AgentSettings> <! -- Use Setting as the node name. You do not need to modify the client interface when considering expansion. Type: easy to differentiate display controls on webpages --> <! -- Proxy customization type. Default Value: Normal. When the webpage is customized by language, take the modification in English or the first language of the list as the standard --> <Setting name = 'customizetype 'type = 'enum'> Normal | DR </Setting> <! -- Product name. When AgentType is DR, it is used to obtain the proxy purchase address --> <Setting name = 'appname' type = 'string'> Wondershare Vedio Convertor </Setting> <! -- Brand name. When AgentType is DR, it is used to obtain the proxy purchase address --> <Setting name = 'her her 'Type = 'string'> Wondershare </Setting> <! -- Purchase address generation method. Default Value: Customize, which is generated by the webpage, no secondary node by default --> <Setting name = 'orderpagegentype 'Type = 'enum'> mimize | Affiliate </Setting> <! -- Affiliate ID, which is valid only when OrderPageGenType is Affiliate. The default value is null --> <Setting name = 'aid 'Type = 'string'> 143724583 </Setting> <! -- Enable the short link for the purchase address of Affiliat. The value of OrderPageGenType is Affiliate. The default value is: 0 --> <Setting name = 'useshortaffiliateorderlink 'type = 'bool'> 0 | 1 </Setting> <! -- Custom output name --> <Setting name = 'outputfilename' type = 'string'> <! [CDATA [1464646. mac-transpod-lite_full879.dmg]> </Setting> </AgentSettings> <! -- Custom information of each language, which is used as a subnode of ages to facilitate unified parsing and expansion --> <ages> <! -- Language name, unified use of CBS background Language data specifications --> <Language name = 'inc'> <Settings> <! -- Product ID, which can be customized in multiple languages --> <Setting name = 'pid 'type = 'stirng'> 11642 </Setting> <! -- Pop-up advertisement is supported. The default value is 1. Whether or not an advertisement can be played depends on the website settings, this is mainly used to close the total control --> <Setting name = 'enabled' type = 'bool '> 1 | 0 </Setting> <! -- Upgrade is supported. Default Value: 1 --> <Setting name = 'enablesupdate' type = 'bool '> 1 | 0 </Setting> <! -- CBS jump link type, which is only valid for InstallJumpPage, UninstallJumpPage, RegisterJumpPage, and UpdateJumpPage. Default Value: jump --> <Setting name = 'cbsjumptype 'type = 'enum'> Jump | Hide | Disable </Setting> <! -- Tisp message supported --> <Setting name = 'tipsenable' type = 'bool '> 1 | 0 </Setting> <! -- Supports pop-up product directory recommendation. Default Value: 1 --> <Setting name = 'enableproductsuit' type = 'bool '> 1 | 0 </Setting> </Settings> <! -- The link address is used as the URLS subnode to facilitate unified resolution --> <URLS> <! -- Do not use '** page' directly as the node name to avoid conflicts between the custom address name and the XML node name specification, such as starting with a number, at the same time, the webpage interface can display the link names based on different products, and you do not need to modify the client interface when scaling up --> <! -- Purchase address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <! -- Differentiate the address type order, jump, comm, and custom to facilitate webpage display classification --> <URL name = 'orderpage' type = 'order' updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Install the redirection address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'installjumppage' type = 'jilp' updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Unmount the jump address. This option is not available for Mac products. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'uninstalljumppage' type = 'dump 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Register the jump address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'registerjumppage' type = 'dump 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Upgrade the jump address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'updatejumppage' type = 'dump 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Company Homepage Address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'homepage' type = 'comm 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Product Homepage Address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'productpage' type = 'comm 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Supports addresses. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'ortpage page' type = 'comm 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Contact customer service address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'contactpage' type = 'comm 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Online help address. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'helponlinepage' type = 'comm 'updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Custom address. A maximum of five addresses can be defined. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = '3dpage' type = 'custom' updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> <! -- Custom address. A maximum of five addresses can be defined. Property updateReserve indicates that the custom information is retained for product upgrade. Default Value: 0. after entering the custom page, the default value is 1 --> <URL name = 'gpupage' type = 'custom' updateReserve = '0 | 1'> <! [CDATA [http: //...]> </URL> </URLS> <! -- Information to be extended, which is pre-processed in the client interface --> </Language> <! -- If the product does not support a Language, you do not need the <Language> node --> <Language name = 'traditional Chinese (HK) '> <! -- Same as above --> </Language> <Language name = 'China'> <! -- Same as above --> </Language> <Language name = 'portuguese '> <! -- Same as above --> </Language> <Language name = 'nginx'> <! -- Same as above --> </Language> <Language name = 'koreanc'> <! -- Same as above --> </Language> <Language name = 'hebrew'> <! -- Same as above --> </Language> <Language name = 'Arabic '> <! -- Same as above --> </Language> <Language name = 'Spanish '> <! -- Same as above --> </Language> <Language name = 'Polish '> <! -- Same as above --> </Language> <Language name = 'German '> <! -- Same as above --> </Language> <Language name = 'French '> <! -- Same as above --> </Language> <Language name = 'Italian '> <! -- Same as above --> </Language> <Language name = 'Spanish (Spain) '> <! -- Same as above --> </Language> <Language name = 'Spanish (Mexico) '> <! -- Same as above --> </Language> <Language name = 'traditional Chinese (TW) '> <! -- Same as above --> </Language> <Language name = 'utch'> <! -- Same as above --> </Language> <Language name = 'Russian '> <! -- Same as above --> </Language> </mizages> </CustomizationSetting>
Encapsulate the xml operation class:
<? Php/*** xml operation base class */class XmlBase {public function _ construct () {}/*** load xml * @ param string $ xml Path or xml string * @ param bool $ whether isXmlStr is an xml string */protected function _ loadXml ($ xml, $ isXmlStr = FALSE) {$ xmlObj = new DOMDocument (); if ($ isXmlStr) {$ xmlObj-> loadXML ($ xmlNewStr );} else {$ xmlObj-> load ($ xml);} return $ xmlObj ;} /*** obtain a label node * @ param $ parentnode parent node * @ param $ tagName Tag Name // not distinguished Case sensitivity * @ return node object */protected function _ getNode ($ parentNode, $ tagName) {$ childNodes = $ this-> _ getNodes ($ parentNode ); foreach ($ childNodes as $ node) {$ nodeName = strtolower (trim ($ node-> nodeName); $ tagName = strtolower (trim ($ tagName )); if ($ nodeName ==$ tagName) {return $ node ;}} return NULL ;} /*** get xml subnode * @ param $ parentNode parent node * @ param $ tagName subnode label // case insensitive */protected functio N _ getNodes ($ parentNode, $ tagName = '') {$ nodes = array (); if ($ tagName) {$ nodes = $ this-> _ getSpecialNodes ($ parentNode, $ tagName);} else {$ nodes = $ this-> _ getAllNodes ($ parentNode);} return $ nodes ;} /*** get all nodes * @ param $ parentNode parent node */protected function _ getAllNodes ($ parentNode) {$ nodes = array (); foreach ($ parentNode-> childNodes as $ node) {if ($ node-> nodeType = 1) {$ nodes [] = $ node ;}} Return $ nodes ;} /*** get the node of the specified label * @ param $ parentNode parent node * @ param $ tagName node name */protected function _ getSpecialNodes ($ parentNode, $ tagName) {$ nodes = array (); $ tagName = strtolower (trim ($ tagName); foreach ($ parentNode-> childNodes as $ node) {$ nodeName = strtolower (trim ($ node-> nodeName); if ($ node-> nodeType = 1 & $ nodeName = $ tagName) {$ nodes [] = $ node;} return $ nodes;}/*** get Node attribute value ** @ param $ node object * @ param $ attrName node name // case insensitive */protected function _ getAttr ($ node, $ attrName) {$ attrName = strtolower ($ attrName); foreach ($ node-> attributes as $ attr) {$ nodeName = strtolower ($ attr-> nodeName ); // $ nodeValue = strtolower ($ attr-> nodeValue); $ nodeType = strtolower ($ attr-> nodeType ); if ($ nodeType = 2 & $ nodeName = $ attrName) {unset ($ attrName, $ nodeName, $ nodeType); Return $ attr-> nodeValue;} return '';}}?>
PS: Here are some online tools for xml operations for your reference:
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Online formatting XML/online compression XML:
Http://tools.jb51.net/code/xmlformat
XMLOnline compression/formatting tools:
Http://tools.jb51.net/code/xml_format_compress
XMLCode Online formatting and beautification tools:
Http://tools.jb51.net/code/xmlcodeformat