Kill lui lei Dog---PHP development app Interface---2 (write XML manually)

Source: Internet
Author: User
Tags php class

Methods for encapsulating communication interfaces

PHP generates XML data

1. Assembling strings

2. Using the System class

DomDocument

XMLWriter

SimpleXML

These classes can be found in the PHP manual.

Such as:

domdocument::createelement-Create new element node (creates a fresh node)

Examples of how to use the manual below:

<? PHP $dom  New  DOMDocument (' 1.0 ',  ' utf-8 ' ); $element  =  $dom -createelement (' Test ', ' This is the  root element! ')  ); // We Insert the new element as root ( child of the document) $dom $element  ); Echo  $dom  -SaveXML ();

The above 1.0 represents the version number of this XML, and Utf-8 represents the encoding of this XML

$dom-createelement (' Test ', ' This is the root element! ');

The first parameter of the pass represents a node, and the second parameter represents a usable data

The above will output:

<? XML version= "1.0" encoding= "Utf-8" ?> < Test > This is the root element! </ Test >

We started trying to write the XML data.

<?PHP class ren{public static function xml () {header ("content-type:text/xml;charset=utf-8"); $xml = "<?xml version= ' 1.0 ' encoding= ' UTF-8 '?>\ n "; $xml. = "<Root>\ n "; $xml. = "<Code>200</Code>\ n "; $xml. = "<message>Data returned successfully</message>\ n "; $xml. = "<Data>\ n "; $xml. = "<ID>1</ID>\ n "; $xml. = "<name>Lisi</name>\ n "; $xml. = "</Data>\ n "; $xml. = "</Root>\ n ";        Echo $xml; }} ren::xml ();

Kill lui lei Dog---PHP development app Interface---2 (write XML manually)

Related Article

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.