View Single Post
Old Jun 23rd, 2005, 6:33 PM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Well, it all depends. XML is just structured data - the XML tags have no specific meaning - their meaning is what you make it out to be. You can read the data and transform it using technologies such as XSLT, or SAX parsers or the DOM. Here's a quick example using Python and minidom, that transforms a simple piece of XML into a HTML document:

XML file (xmlpage.xml):
<page>
  Hello there. <link url="http://www.google.com">This links to Google</link>. This is some <bold>bold text</bold>. Bye bye!
</page>

Python script:
import sys
import xml.dom.minidom as minidom

document = minidom.parse("xmlpage.xml")
page = document.childNodes[0]
print "<html>"
print "<head><title>Generated page</title></head>"
print "<body>"
for child in page.childNodes:
    if child.nodeType == minidom.Node.TEXT_NODE:
        sys.stdout.write(child.data)
    elif child.nodeType == minidom.Node.ELEMENT_NODE:
        if child.nodeName == "link":
            sys.stdout.write('<a href="%s">%s</a>' % (child.getAttribute("url"), child.childNodes[0].data))
        elif child.nodeName == "bold":
            sys.stdout.write('<strong>%s</strong>' % (child.childNodes[0].data))
print "</body>"
print "</html>"

Output:
<html>
<head><title>Generated page</title></head>
<body>

  Hello there. <a href="http://www.google.com">This links to Google</a>. This is some <strong>bold text</strong>. Bye bye!
</body>
</html>
Cerulean is offline   Reply With Quote