Page 1 of 2

xml

Posted: Tue Aug 09, 2005 6:00 am
by shiznatix
i have seen xml code and whatnot but i dont see what xml can do that html can not do. whats so great about xml anyway?

Posted: Tue Aug 09, 2005 7:31 am
by feyd
Extensible. :)

You can build your own "standard" of tags/attributes and use them in many fashions. Basically, it's a way of creating a structured document with a very flexible set of rules that everyone can understand quite easily. :)

Posted: Tue Aug 09, 2005 7:32 am
by shiznatix
but it does not do anything that html can not do?

Posted: Tue Aug 09, 2005 7:34 am
by feyd
html is now a form of xml.. basically. hence XHTML.

XML is free from the restrictions of presentation. The presentation is entirely up to what's reading it. It's pretty much literally just a data system.

Re: xml

Posted: Tue Aug 09, 2005 8:25 am
by Roja
shiznatix wrote:i have seen xml code and whatnot but i dont see what xml can do that html can not do. whats so great about xml anyway?
Great question!

XML is put simply, a language used for presenting *data*. Nothing else.

In my game, we now have an xml-based schema for our database tables. It looks like this:

Code: Select all

<?xml version="1.0"?>
<schema version="0.3">
    <table name="vote">
        <field name="vote_id" type="I1">
            <autoincrement/>
            <key/>
        </field>
        <field name="vote_text" type="X"></field>
    </table>
</schema>
This is a simple example, but I think you can see most of the power here. Its easily parsable by script, its fairly straightforward in terms of data, and it can even be transformed by xsl for display to the user as xhtml.

You asked what makes it better than html. First and foremost, computer processing. Processing HTML (or more specifically, tag-soup) is hideously complex. Tags aren't matched. Required attributes might not be present. Elements may or may not have endings. Contents may or may not be encoded correctly.

Trying to write an html parser is beyond hard - its nearly impossible, because as soon as you think you have it working, you end up with another page that isn't compliant enough for your parser. Even parsers like Snoopy, built from the ground up with the awareness of tagsoup, have problems with some pages.

Compare with XML. Parsers are so simple for XML that there are now native extensions for it in php5. You can build a tree, pick out specific elements, and you know it will work because xml is required to be valid. Thats the huge difference from html.

On top of that, its better because its faster. "Faster?" You say?

Yes. Imagine a page full of font tags, tables, marquee tags, and other tag soup mess. Then picture in your mind removing EVERYTHING except the data. See the difference? Thats the power of xml v. html for moving raw data. Its faster, its simple, and its amazingly useful.

It powers gmail, google maps, amazon, and dozens of other sites. It is becoming the definitive best solution for moving data on the web.

That cover most of your questions?

Posted: Tue Aug 09, 2005 8:38 am
by Grim...
I take it CSS is used for the 'displaying'?

Posted: Tue Aug 09, 2005 9:10 am
by feyd
CSS has zero baring on XML. :? It is entirely display-side.

Posted: Tue Aug 09, 2005 9:18 am
by Roja
Grim... wrote:I take it CSS is used for the 'displaying'?
Nope.

You use XSL to "transform" the XML into XHTML. Then, yes, you can use CSS to control the formatting, layout, and so on.

Posted: Tue Aug 09, 2005 9:26 am
by Grim...
So it's a bit like storing data in a public database and letting anyone get at it and display it how they like, right?

Posted: Tue Aug 09, 2005 9:41 am
by Roja
Grim... wrote:So it's a bit like storing data in a public database and letting anyone get at it and display it how they like, right?
Very close - its not a database (although you can store xml in a databse), but it is a source of data. You can choose to make it public, like many sites do (RSS), or it can be private.

But the last part was dead on: Its data, and what you do with that data is completely up to you.. transform it to xhtml, style it with css, display it, parse it, whatever you like. That is the true power of raw, accessible, parsable data. Its easy to work with. :)

Posted: Thu Aug 11, 2005 4:01 pm
by neophyte
What's the best website for learning XML and PHP?

Posted: Thu Aug 11, 2005 4:44 pm
by timvw
Have a look at http://www.w3schools.com. Meaby it's not the best, but i usually like their articles...

Posted: Thu Aug 11, 2005 5:11 pm
by patrikG
I haven't found many good articles on XML and PHP on the web. As a matter of fact, most were outdated. I know it's not extremely helpful, but I've learned most from either books or looking at how other people use XML.

Posted: Thu Aug 11, 2005 9:37 pm
by m3mn0n
Wrox Publishing has a couple great books about XML and XML + PHP.

Posted: Fri Aug 12, 2005 8:17 am
by theda
XML is mainly used for open-sourced projects and RSS. And you can appy CSS to an XML file... W3C's examples do it. http://www.w3schools.com/xml/cd_catalog_with_css.xml