xml

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

xml

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. :)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

but it does not do anything that html can not do?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: xml

Post 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?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

I take it CSS is used for the 'displaying'?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

CSS has zero baring on XML. :? It is entirely display-side.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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. :)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

What's the best website for learning XML and PHP?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Have a look at http://www.w3schools.com. Meaby it's not the best, but i usually like their articles...
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Wrox Publishing has a couple great books about XML and XML + PHP.
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post 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
Post Reply