Reading and writing Extensible Markup Language (XML) in PHP may seem a bit scary. In fact, XML and all of its related technologies can be scary, but reading and writing XML in PHP is not necessarily a scary task. First, you need to learn a little bit about XML: what it is and what it does with it. Then you need to learn how to read and write XML in PHP, and there are a number of ways you can do it.
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 simply defines the tags and the attributes of those tags. Well-formed XML tags look like this:
This test for php100
This one The tag contains some text: Jack Herrington. XML tags that do not contain text look like this:
There is more than one way to write an item 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 The tag contains the first and last attributes:
You can also encode special characters with XML. For example, the,& symbol can be encoded like this:
&
XML files that contain tags and attributes are well-formed if formatted like an example, which means that the tokens are symmetric and the characters are encoded correctly. Listing 1 is an example of well-formed XML.
Listing 1. Examples of XML book columns
Jack Herrington
PHP Hacks
OReilly
Jack Herrington
Podcasting Hacks
OReilly
The XML in Listing 1 contains a list of books. Parent tag Contains a set of tags, each Tags are also included, <title>And</title> Mark. XML documents are correct when the markup structure and contents of an XML document are validated by an external schema file. Schema files can be specified in different formats. For this article, all you need is well-formed XML.
If you think that XML looks much like Hypertext Markup Language (HTML), then you are right. Both XML and HTML are markup-based languages, and they have many similarities. However, it is emphasized that although XML documents may be well-formed HTML, not all HTML documents are well-formed XML. A newline tag (BR) is a good example of the difference between XML and HTML. This newline tag is well-formed HTML, but not well-formed XML:
This is a paragraph
With a line break
This newline tag is well-formed XML and HTML:
This is a paragraph
With a line break
If you want to write HTML as well-formed XML, follow the Extensible Hypertext Markup Language (XHTML) standard of the Board (see Resources). All modern browsers can present XHTML. Also, it is much easier to use XML tools to read XHTML and find the data in the document than to parse the HTML.
http://www.bkjia.com/PHPjc/486121.html www.bkjia.com true http://www.bkjia.com/PHPjc/486121.html techarticle reading and writing Extensible Markup Language (XML) in PHP may seem a bit scary. In fact, XML and all of its related technologies can be scary, but reading and writing XML in PHP is not necessarily ...