20.0 Introduction


XML seems to be a buzzword in the Web industry these days. No matter what job you're working on, it seems to be a requirement that you know XML. Whether you are a network administrator or HTML coder , you should probably try to learn what XML is (even if it's to just put it on your resume). In this chapter, we discuss how PHP enables you to work with XML.

A Quick Overview of XML

Before I explain how PHP handles XML, perhaps we should talk a little about XML itself. XML, or Extensible Markup Language, enables us to create structured documents. For example

 <recipe>     <title>Mom's Meatloaf</title>     <instructions>         Pre-heat oven to 400 degrees. Saute chopped onions till         almost translucent. Chop celery, carrots and parsley into         little pieces. Stir sauted onions into celery, carrot, parsley         mixture. Add meat, tomato sauce, eggs and wine, and spices         (salt, pepper, garlic, Italian spice). After thoroughly mixed         add bread crumbs till firm. Cover bottom of baking pan with         a little tomato sauce and virgin olive oil. Spread meatloaf         mixture evenly. It cooks faster if in a shallow pan and only         1-2 inches thick then if in a loaf pan. Cover entire top         surface with tomato sauce. Lower oven temperature to 350         degrees and cook until toothpick in center comes out clean         (and no pink) about a hour to a hour and half.     </instructions>     <ingredients>         <item>             <name>Onions</name>             <amount>1 large onion</amount>         </item>         <item>             <name>Celery</name>             <amount>3 stalks</amount>         </item>         <item>             <name>Carrots</name>             <amount>Two medium sized carrots</amount>         </item>         <item>             <name>Chopped Sirloin</name>             <amount>1.75 lbs.</amount>         </item>         <item>             <name>Parsley</name>             <amount>1/4 cup chopped</amount>         </item>         <item>             <name>Eggs</name>             <amount>4</name>         </item>         <item>             <name>Tomato Sauce</name>             <amount>1/2 cup</amount>         </item>         <item>             <name>Salt, Pepper, Garlic, Italian spice</name>             <amount>As much as necessary</amount>         </item>     </ingredients> </recipe> 

This is one way you might represent an entry into a cookbook (this is my mom's recipe). The tags in the document describe the content that is contained within them, rather than describing the way that the content is formatted (as HTML does). That is basically all there is to XML. The simplest description is to say that XML is HTML except that you can use any tags you want, and the tags describe the data rather than the way the data is displayed. There are some markup differences between XML and HTML (for example, empty tags such as <br> must contain a trailing slash: <br/> ), but the fundamental conceptual difference is that one (HTML) represents the way to display content, the other (XML) is a way to structure the content.

This book can in no way be a full-fledged tutorial on XML. The subject is too broad for me to do it justice in just one chapter, so for more information on the XML standard, see XML by Example, published by Que Publishing.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net