PHP XML2 operation: loading XML documents using DOM objects
Source: Internet
Author: User
In XML entry 5: using PHP to operate xml_parser, we learned how to use xml_parser to parse XML documents. However, xml_parser cannot modify or create XML documents. From today on, we will learn how to use the php dom extension module to enrich and flexibly operate XML documents. in "XML entry 5: using PHP to operate xml_parser, we learned how to parse XML documents through xml_parser in PHP. However, xml_parser cannot modify or create XML documents. From today on, we will learn how to use the php dom extension module to perform richer and more flexible operations on XML documents.
First, let's introduce the DOM extension module of PHP. It regards each node in the XML document as an object tree and can traverse this tree at will to access all elements, attributes, and text nodes in this document. You can also flexibly modify node values and create a new XML document.
Let's take a look at how to use DOM to load an XML file, convert it to a string, and output it on the screen.
The php code is as follows: Load ("./1.xml"); // Convert the loaded xml file into a string $ xml = $ doc-> saveXML ();?> Printed on the screen will be: Jiang Shen 23 male Shanghai Liu Hao 26 male Shanghai View source code, will see: Jiang Shen 23 Male Shanghai Liu Hao 26 Male Shanghai
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.