Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   XML (http://www.programmingforums.org/forum28.html)
-   -   convert xml to html (http://www.programmingforums.org/showthread.php?t=4571)

raikkonen Jun 23rd, 2005 3:54 AM

convert xml to html
 
hi guys.. i need some help here... can someone tell mi how could i publish xml formated documents to html formated documents?? thanks ..

Cerulean Jun 23rd, 2005 6:33 PM

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>


raikkonen Jun 26th, 2005 9:50 PM

hmmm thanks man.. i dont quite know what is python script. could you tell me? thanks in advance.

Cerulean Jun 27th, 2005 3:16 PM

Hm, I think you may be over-shooting your mark in your attempt of this, with no programming knowledge.
Possibly look into a system that does this for you?

skuinders Jun 27th, 2005 3:24 PM

XSLT is made for conversions such as this

http://www.w3.org/TR/xslt

raikkonen Jun 27th, 2005 9:52 PM

actually i new to programming. this is a assignment so i have no choice. but anyway thanks guys. i'll do the research. thanks for the help again.

frankish Oct 27th, 2005 9:16 PM

Do you know C++. There is something on www.sourceforge.net called TinyXML. I have downloaded it but I haven't used it.


All times are GMT -5. The time now is 2:15 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC