NetworkClue.com
NetworkClue Home PageHome Contact UsContact ConsultingConsult
Bulletin Board
Internet Services covers Secrets to hosting websites, Hosting your own web server, and using DNS Servers.Operating Systems leads you through the decision of Linux vs. Windows, ideal installations and setups to create an efficient and redundant environment for your business, and great features to make management easier.Routing & Firewalls contains articles that will allow you to take control of your router. Learn how to protect your company with access lists and advanced firewall techniques.Hardware answers the common questions about Switches vs. Hubs, recommends SysAdmin Tools, and recommendations for adequate power protection.Utilities will cover fighting spam, using Anti-Virus programs effectively and the must haves for every administrator's software toolbox.

Bulletin Board

XML in a nutshell

Paul Streder

XML is a way of organizing data. If you understand the way HTML works, you will understand XML. XML is formatted exactly the same as HTML (an opening tag, and a closing tag).

So where HTML has predefined tags (like <html> and <body> and <table>) in XML, those mean nothing except what you want them to.

If you have a whole bunch of information on something (such as a car) you could organize it like so:

<car>
  <make>Nissan</make>
  <model>350Z</model>
  <hp>287</hp>
  <torque>274</torque>
</car>

As you can see, the data is organized in a STRICT manner (any deviation in XML formatting will result in an unvalid XML document).

Now after you have generated your XML doc (either by hand or as a return from SQL server), you cant just display this data to a user and have it look pretty (or even assume the user could figure out what you were trying to display). So you need to create an XSL document. These xsl documents take XML and display it as HTML. an example that would display the XML code above:

<xsl:template match="car">
<table border="0" cellpsacing="0" cellpadding="0">
<tr>
<th>Car: </th>
</tr>
<tr>
<td>Make: </td>
<td><xsl:value-of select="make"/></td>
</tr>
<tr>
<td>Model: </td>
<td><xsl:value-of select="model"/></td>
</tr>
<tr>
<td>Horse Power: </td>
<td><xsl:value-of select="hp"/></td>
</tr>
<tr>
<td>Torque: </td>
<td><xsl:value-of select="torque"/></td>
</tr>
</table>
</xsl:template>

The xsl:value will take the value of the child node to "car" with the name specified in the select statement.

One big difference between XSL and HTML, is the strict standards. EVERY tag must be closed, and every attribute must have quotes around it.

You can use XML strictly as a storage medium, or you can use it as a SOAP call, and send data to a server in XML format and have the server parse the XML for values. XML is extremely versatile and is the key to using mobile devices online (displaying web docs on cell phones, pdas, etc).

Using XML with ASP

In ASP, after you load an XML Docs & the XSL docs into an object

Dim xmlDoc
Set xmlDoc=Server.CreateObject("MSXML2.DOMDocument.4.0")
xmlDoc .load Server.MapPath("data/sections.xml")
Dim xslDoc
Set xslDoc=Server.CreateObject("MSXML2.DOMDocument.4.0")
xslDoc.async=FALSE
xslDoc.load Server.MapPath("templates/default.xsl")

You will transform the data in the asp:

strOutputHTML=xmlDoc.transformNode(xslDoc)

Where strOutputHTML is the HTML string you response.write to the user

Article last reviewed: 01/24/2003


del.icio.us

Created by: Digital Foundation, inc.

Copyright © 2002-2005 Digital Foundation, inc.   www.networkclue.com

All content of the NetworkClue website is copyrighted. Articles, notes, outlines, and all other materials may not be stored on the Internet or sold or placed by themselves or with other material in any electronic or printed format in whole or part. However materials may be referenced by links to the site.

 

 

Related Articles:
Handy ASP
Handy HTML