homepage Welcome to WebmasterWorld Guest from 50.17.21.7
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Xml
What is xml why when should we use it
Ove




msg:702309
 6:18 pm on May 29, 2002 (gmt 0)

What is xml why when what were should we use it.

Can we have that good explenation you did about the .net post??

/Ove

 

Xoc




msg:702310
 6:47 pm on May 29, 2002 (gmt 0)

XML is merely a way of encoding data as text using markup. Say you want to keep track of some books, you could encode that data as:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<books>
<book>
<author>Jack Vance</author>
<title>Lost Moons</title>
</book>
<book>
<author>Jack Vance</author>
<title>Cugel Saga</title>
</book>
<book>
<author>Roger Zelazny</author>
<title>Dilvish, the Damned</title>
</book>
</books>

Looks a lot like HTML, except the tags are not HTML tags. I just made the tags up as I needed them.

Now how can you use that info? Well, I can move it around just by sending you the text. I can parse it and get the pieces. Think of it much the same way that you would think of a database, except that it is a lot simpler and non-proprietary.

One thing I can do is apply an XSLT (eXtensible Style Language Transformation) style sheet to it. Think of XSLT as a simple scripting language. The script, though, is written as XML (this starts getting recursive after a while!). For example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="books">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>

<xsl:template match="book">
<li><xsl:value-of select="author"/>: <xsl:value-of select="title"/></li>
</xsl:template>
</xsl:stylesheet>

The output of the transformation is:


  • Jack Vance: Lost Moons
  • Jack Vance: Cugel Saga
  • Roger Zelazny: Dilvish, the Damned

Now how you do that applying depends on what environment you are developing under.

Another way to work with it is to use the Document Object Model (DOM) to walk through the nodes. You need a parser, but the interface to the parser is a W3 spec, found here: [w3.org...]

There are also other different parsers.

So XML is just marked up data. The question is what do you want to do with the data? I tend to use XML in many places that I would formerly have used a database as it is easier to write and maintain.

Ranger




msg:702311
 7:03 pm on May 29, 2002 (gmt 0)

Hi Xoc:

I'm new to the concepts of XML: so is that completely cross-browser friendly?

Meaning the now-dreaded NN4 - can it parse XML?

Also: are there any HTML to XML programs out there (I mean, I get that you need to mark the data up, but anything that would take the basic HTML and make it lower case, etc.)

Finally: can you use XML for things like navigation menu includes?

Xoc




msg:702312
 7:08 pm on May 29, 2002 (gmt 0)

If you do your processing on the Server Side, only HTML is delivered to the client. So as long as your HTML works in Netscape, you have no problem. IE starting with version 4 has client side support, and I think Netscape 6 does too, but client-side XML will always be proprietary until the W3C adds extensions to the XHTML spec. I recommend server-side processing.

As far as converting HTML to XHTML, there is a program called HTML Tidy available on the W3 web site that will do it for you. Available from here: [w3.org ]. XHTML is HTML coded to the XML rules. Questions about it should be posted in the HTML forum.

XML is just data. So what you use it for and how you use it is up to you. It doesn't implicitly do menus.

Ranger




msg:702313
 7:13 pm on May 29, 2002 (gmt 0)

Great info, Xoc, many thanks.

Server-side processing: what do you use? Are there ASP, CFM, and PHP "tags" that would do it? Is that what you mean?

Or are you talking about some specific programs that sit in a CGI-bin, etc?

Ove




msg:702314
 7:15 pm on May 29, 2002 (gmt 0)

Thanks alot for this info :)

/Ove

Xoc




msg:702315
 7:24 pm on May 29, 2002 (gmt 0)

See this post for an example of how you'd apply XSLT to XML on an Active Server Page: [webmasterworld.com...]

For other environments, you'd need a different parser and different scripting code. Depends on the environment on how that would work. But the basic scheme is the same. You get the XML, you get the XSL, you apply one to the other producing HTML, you send the HTML to the client.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved