PHP operation XML document fetching data "PHP parsing xml"
1.php manipulating the DOM "document Object Model" Each document forms a tree-like model "Dom" from the root node
DOM document class: DOMDocument: Document class Domnodelist: Node List class Domnode: node class DomElement: Element class
These four classes can be manipulated against DOM documents
2. Manipulating DOM objects
(1) Create DOM object: $dom = new Document ();//Restrict the version of the object, encode (2) load the XML file $dom->load ();//load the specified XML file (3) Select the data on the node "can also be manipulated" The operating node is relatively difficult to read directly. The operation of the node is to establish a relationship between the nodes to operate "http://www.jb51.net/article/21472.htm"
Here PHP operation node behavior and JS operation HTML node implementation of the page structure is similar to "substantially cause the document's node itself, resulting in the operation of the documentation syntax is roughly the same" "the operation of adding or deleting nodes should be noted"
Two PHP Common library PHP DOM: The operation of the document "Delete and change operation" SimpleXML: query operation
3.SimpleXML: Traverse documents very fast "tune interface Common"
(1) Read data: Simpleelement simplexml_load_file () "read data from an XML file" returned is not a data type inside PHP, but a "simplexml" instance and not an object and resource " Simpleelement::__construct () "Reading data from an XML string"
(2) After the data is loaded, the data is processed in all the SimpleXML libraries to the data node Read method
"Write your own Data interface: The XML format of the data output to the client is the interface" generate XML Information "two, splicing strings and generate interface files (using the header file type Provisions)" Add to the node "or the addition of attributes" to build the interface
4.xpath "http://www.w3school.com.cn/xpath/" XPath is a way to find properties and elements in an XML document. "Still need to load the file" XPath syntax is similar: locating a file in a file system "is similar to using path location to get Files" XPath uses the syntax: "The difference between a single slash and a double slash"/student: Returns information//student for the student element: Returns the hierarchy of all rules following a double slash in the element "equivalent to a rule definition"
Example: $xml =simplexml_load_file (' demo05.xml ');
Returns the name of everyone $data = $xml->xpath ('/persons/person/name '), or the equivalent of matching the name element to the data within the foreach ($data as $value) {echo $value .‘ <br> '; }
The above is a simple XPath syntax
It is not necessary to use complex XPath syntax for queries within the interface itself "but there is a need to be aware of this match"
5. Online dictionary is the function of ctrl+f to the browser the local input is a form, then a request to the server, the server returns a set of corresponding data "XML format results" displayed in the search results location. "One Ajax, one result data splicing process" can be completed
"The idea of the interface" in fact, here is a multi-platform for the common data operation of the idea of "interface", through the results of data query stitching into an interface file "paging", and then each platform according to the interface file for targeted display "although inefficient, but the data processing and reuse, good"
Single and double quotation marks: The key is the problem of embedding single quotes inside double quotes: "Use in SQL statements and XPath" variables within the double quotation mark can parse normally, but because the SQL statement and XPath indicate that the field requires a single quotation mark "String type", there is a single quotation mark. $sql = "SELECT * from ' $table ' where ...";//Such syntax, even if there is a single quotation mark outside the variable, does not affect the resolution of the variable
The above is about the contents of the XML operation "Notice the cognition of the interface and the effect of the SimpleXML library and the XPath, PHP Dom to manipulate the document node"
PHP Operations Dom,simplexml, XPath read XML, and XML as a data interface for the use of the understanding