For example consider the
following XML where we describe the properties of a student:
OzniakIn the above example, there are three attributes to this student tag??”age, class, and
title. Using PHP we can easily manipulate them too. In the coming sections we will
learn how to parse XML documents, or how to create XML documents on the fly.
Introduction to SimpleXML
In PHP4 there were two ways to parse XML documents, and these are also available
in PHP5. One is parsing documents via SAX (which is a standard) and another one is
DOM. But it takes quite a long time to parse XML documents using SAX and it also
needs quite a long time for you to write the code.
In PHP5 a new API has been introduced to easily parse XML documents. This was
named SimpleXML API. Using SimpleXML API you can turn your XML documents
into an array. Each node will be converted to an accessible form for easy parsing.
Chapter 8
[ 197 ]
Parsing Documents
In this section we will learn how to parse basic XML documents using SimpleXML.
Let's take a breath and start.
$str = <<< END
nowhere@notadomain.tld
unknown@unknown.
Pages:
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213