Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Example 1

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
Can someone explain to me exactly what XML is? I know what it is capable of, but I have seen one adaptation of it. For example, people say that if something is coded in XML, it can go from HTML to MS Word, etc. Can anyone make me an example that shows XML's capabilities and advantages?

Thanks so much!

Ryan ;-]
 
XML is a method of encoding data independent of its representation. The tags in XML tell the various rendering programs what each "field" is called and what the value for that field is.

The rendering program will then go through and pick and chose which tags and values it will display.

For example, you could have a file of newspaper articles like this (snippet, not full file)

<article loc=1>
<title>Boy Bites Dog</title>
<byline>John Jones</byline>
Jimmy Smith ate a hot dog today.
</article>
<article loc=2>
<title>Freak Accident</title
<byline>Joe Smith</byline>
A parked car struck a truck traveling in the 3rd lane of Main Street last night.
</article>

One PHP or XSL page could parse through looking for Title and Byline (and the loc attribute) and create a list of links which would start another PHP page which would display the full text of one story.

Output of first page: (fragment only)
<a href=secondpage.php3?loc=1>Boy Bites Dog, by John Jones</a>
<a href=secondpage.php3?loc=2>Freak Accident, by Joe Smith</a>

Output of second page, loc=1: (fragment only)
<h1>Boy Bites Dog</h1>
<h2>by John Jones</h2>
<p>Jimmy Smith ate a hot dog today.</p>

Two one line stories doesn't look like such a big deal, but think of the implications for several hundred one to 20 paragraph stories.

Try for a free magazine subscription. It will help you find out what tools and methodologies and concepts are in use and under development.

Rose/Miros
 
Thanks! XML seems really good, but can't you do the same thing with the info contained in your XML file if it were entered into a database? Furthermore, how does is the XML file read and converted to something like a Word document?

Ryan ;-]
 
These are the advantages of XML over a database (at least from my point of view).

Normal, human readable/modifiable ASCII data.
No restrictions on field sizes.
Records can be nested within one file without having to go to a full fledged relational model.
<Book><Author>John Smith</Author><Author>Jane Doe</Author></Book>
With careful coding in the XSL (i.e. default values), you can add more fields without having to add those fields to EVERY XML file (or record inside an XML file).

For XML to HTML, you'd use something like PHP3 or XSL.

For XML to Word, you'd need either custom software or maybe MS will get their stuff together and let you load up a template in Word, then import XML. Word is currently using &quot;data islands&quot; which means they take a Word document and put XML tags before and after it. This means you've still gotta be able to read or write Word documents to deal with their XML files.

There are already translation programs to go back and forth between XML and various database formats.

You can also write your own programs to read XML with expat (C/C++), python (scripting language), Lark or Saxon (Java).

Rose/Miros
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top