PHP self-learning path ----- basic introduction to XML programming (Xpath technology, simpleXml Technology)

Source: Internet
Author: User

The core idea of XPath design can be quickly introduced by xpath to locate the desired node. The main purpose is to describe the location of a node relative to another node. All qualified nodes can be obtained and become [location paths]. Xapth is mainly used to query information in XML documents. You can use path expressions to parse XML files and read the data in XML files. The following is a case study. The XML file is as follows (simplexml. xml): [php] <? Xml version = "1.0" encoding = "UTF-8"?> <Books> <book house = "qinghuachubanshe"> <code> sb001 </code> <price> 200 </price> <author> xiaoming </author> <title> tianlongbabu </title> </book> <book house = "beidachubanshe"> <code> sb002 </code> <price> 400 </price> <author> daming </author> <title> xiaoaojianghu </title> </book> </books> PHP code is as follows: [php] <? Php // 1 create a DOMDocument object $ dom = new DOMDocument ("1.0", "UTF-8"); // 2 load the Xml file $ dom-> load ("simplexml. xml "); // 3 convert to the DomXPath object $ xpath = new DOMXPath ($ dom ); // 4 search for work $ node_list = $ xpath-> query ("/books/book/title"); echo "Total ". $ node_list-> length. "<br/>"; for ($ I = 0; $ I <$ node_list-> length; $ I ++) {$ node = $ node_list-> item ($ I); // var_dump ($ node_list);/* foreach ($ node as $ key => $ val) {echo

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.