1. XML Format specification:
① must have a root element
② cannot have spaces, cannot be in numbers or. Start, case sensitive
③ non-overlapping nesting
④ Attribute double quotation marks (the browser is automatically corrected into double quotes)
⑤ Special symbols to use entities
⑥ annotations are the same as HTML
Although complex data can be described and transmitted, its resolution is too complex and large, so implementation is rarely used.
Cases:
- <? XML version= "1.0" encoding="UTF-8"?>
- <root>
- <arrayList>
- <array>
- <src>images/banner.jpg</src>
- <newpirce>12.00</newpirce>
- <oldprice>30.00</oldprice>
- </Array>
- <array>
- <src>images/banner.jpg</src>
- <newpirce>12.00</newpirce>
- <oldprice>30.00</oldprice>
- </Array>
- </arrayList>
- </root>
2. How to get the XML file in PHP:
①header to write Text/xml.
②
file_get_contents 获取文件内容
This has been removed in over 5.4 versions. So you want to modify the file_get_contents ("Php://input") to get the value of the XML.
- <?php
- Header (' Content-type:text/xml;charset=utf-8 ');
- / * Request Response content format when transferring data in XML format is text/xml*/
- /*file_get_contents Get File contents * /
- $xml = file_get_contents (' 01.xml ');
- / * Output XML content * /
- echo $xml;
- ?>
3. Ajax
How to get the response data in XML format:
Responsexml
- var xhr = new XMLHttpRequest;
- Xhr.open (' get ',' 01.php ');
- Xhr.send (null);
- Xhr.onreadystatechange = function () {
- if (xhr.status = = && Xhr.readystate = = 4) {
- / * Gets the content returned to the XML format as a DOM object document*/
- var xml = Xhr.responsexml;
- / * You can get the data to XML via the selector * /
- Console.log (Xml.queryselectorall (' array ') [0].queryselector (' src '). InnerHTML);
- }
- }
XML (How to get an XML file in PHP/ajax how to get the response data in XML format)