supports multiple attributes:
<?xml version="1.0"?>
<!DOCTYPE Travelpackages SYSTEM "sample.dtd">
<Travelpackages>
<Country name="Cuba">
<City name="Cayo Coco">
<Resort name="Club Tryp Cayo Coco" rating="4" typeofholiday="beach"
watersports="true" meals="true" drinks="true">
<Package dateofdep="5/8/98" price="879"/>
<Package dateofdep="5/1/98" price="879"/>
</Resort>
</City>
<City name="Varadero ">
<Resort name="Sol Club Paleras" rating="3" typeofholiday="beach"
watersports="false" meals="true" drinks="false">
<Package dateofdep="5/30/98" price="799"/>
<Package dateofdep="5/23/98" price="879"/>
<Package dateofdep="5/16/98" price="889"/>
</Resort>
</City>
</Country>
</Travelpackages>
To convert this XML to SML format, the attributes should be changed to elements. Let's take a look at the sample.xml document in SML format:
<Travelpackages>
<Country>
<Country_name>Cuba</Country_name>
<City>
<City_name>Cayo Coco</City_name>
<Resort>
<Resort_name>Club Tryp Cayo Coco</Resort_name>
<Resort_rating>4</Resort_rating>
<Resort_typeofholiday>beach</Resort_typeofholiday>
<Resort_watersports>true</Resort_watersports>
<Resort_meals>true</Resort_meals>
<Resort_drinks>true</Resort_drinks>
<Package>
<Package_dateofdep>5/8/98</Package_dateofdep>
<Package_price>879</Package_price>
</Package>
<Package>
<Package_dateofdep>5/1/98</Package_dateofdep>
<Package_price>879</Package_price>
</Package>
</Resort>
</City>
</Country>
</Travelpackages>
<b>In XML white space is ignored unless you explicitly preserve
it.</b>
This sample XML document while short is sufficiently complex to
show the differences in how the different APIs handle XML. This
sample has most of the characteristics that we will find in most
XML documents. We will change the XML format a little bit when
dealing with the different APIs so we can get the code to work.
You'll need to remember to check your XML to ensure that it
works with the API that you choose.
PHP and XML
PHP allows support for four ways to interact with an XML
document. They are:
-
Simple API for XML (SAX)
-
Document Object Model API (DOM)
-
PHP Recordset API for XML (PRAX)
-
Sablotron (XSLT)
Each API interacts with the same XML data in different ways, and
all three support or don't support slightly different parts of
XML.
The XML Framework
Professional PHP4 Programming
Verifying XML Support