Xml:extensible Markup Language, an extensible label language, is itself a string format used to describe bulk composite data,
Grammatical features:
(1) All data is placed in the label
(2) The entire XML string has and can have only one root tag
(3) All label names can be customized, but are strictly case-sensitive, and the start and end tags must be exactly the same
(4) Each label can be custom attributes, the attribute must have a value, the value must be enclosed in single quotation marks/double quotation marks.
(5) Each label can be defined as any sub-label, the label can be nested, but not cross
Note: The difference between HTML and XML
HTML syntax is arbitrary; XML syntax is strict;
HTML tags are predefined; XML tags are custom-defined;
HTML is used to describe the structure of a webpage; XML tags are used to describe data;
Here's an XML that we need to carry data, and then we're going to build XML-formatted data through PHP.
<?xml version= "1.0" encoding= "UTF-8"?> <productlist><product pid= "101" ><pname> Samsung </pname ><price>35.50</price><pic>1.jpg</pic></product><product pid= "102" >< pname> SanDisk </pname><price>45.50</price><pic>2.jpg</pic></product>< Product pid= "103" ><pname> Kingston </pname><price>30.50</price><pic>3.jpg</pic> </product></productlist>
PHP constructs XML structure data and responds
<?phpheader (' Content-type:application/xml '); $conn = Mysqli_connect ("127.0.0.1", "Root", "" "," Dangdang ", 3306); $ sql = "SET NAMES UTF8"; Mysqli_query ($conn, $sql); $sql = "SELECT * from book"; $result = Mysqli_query ($conn, $sql); $list = Mys Qli_fetch_all ($result, MYSQLI_ASSOC); $str = "<?xml version= ' 1.0 ' encoding= ' UTF-8 '?>"; $str. = "<productlist > "; foreach ($list as $b) {$str. =" <product pid= ' $b [bid] ' ><pname> $b [bname]</pname><price>$ b[price]</price><pic> $b [pic]</pic></product> ";} $str. = "</productlist>"; Echo $str;
Receive XML and parse because XML belongs to the Xmldom object can only be parsed using the core DOM method
<!doctype html>
Build and parse data in XML format using native Ajax and PHP