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)