Home >Backend Development >PHP Tutorial >Detailed explanation of reading and writing XML and DOM in PHP_PHP Tutorial
Reading and writing Extensible Markup Language (XML) in PHP can seem a little scary. In fact, XML and all its related technologies can be scary, but reading and writing XML in PHP doesn't have to be a scary task. First, you need to learn a little about XML: what it is and what to do with it. Then, you need to learn how to read and write XML in PHP, and there are many ways to do this. This is a paragraph This is a paragraph
What is XML?
XML is a data storage format. It does not define what data is saved, nor does it define the format of the data. XML just defines tags and the attributes of those tags. A well-formed XML tag looks like this:
This
There's more than one way to write something in XML. For example, this tag forms the same output as the previous tag:
You can also add attributes to XML tags. For example, this
Special characters can also be encoded in XML. For example, the & symbol can be encoded like this:
&
An XML file containing tags and attributes is well-formed if it is formatted like the example, meaning that the tags are symmetrical and the characters are encoded correctly . Listing 1 is an example of well-formed XML.
Listing 1. XML book list example
The XML in Listing 1 contains a list of books. The parent tag
If you think XML looks a lot like Hypertext Markup Language (HTML), you're right. XML and HTML are both markup-based languages and they have many similarities. However, it is important to note that while an XML document may be well-formed HTML, not all HTML documents are well-formed XML. The newline tag (br) is a good example of the difference between XML and HTML. This line break tag is well-formed HTML, but not well-formed XML:
With a line break
With a line break
If you want to write HTML in the same format For good XML, follow the W3C committee's Extensible Hypertext Markup Language (XHTML) standard (see Resources). All modern browsers can render XHTML. Furthermore, you can use XML tools to read XHTML and find the data in the document, which is much easier than parsing HTML.
http://www.bkjia.com/PHPjc/486121.html
www.bkjia.com