Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 23rd, 2005, 3:54 AM   #1
raikkonen
Newbie
 
Join Date: Jun 2005
Posts: 29
Rep Power: 0 raikkonen is on a distinguished road
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 ..
raikkonen is offline   Reply With Quote
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
Old Jun 26th, 2005, 9:50 PM   #3
raikkonen
Newbie
 
Join Date: Jun 2005
Posts: 29
Rep Power: 0 raikkonen is on a distinguished road
hmmm thanks man.. i dont quite know what is python script. could you tell me? thanks in advance.
raikkonen is offline   Reply With Quote
Old Jun 27th, 2005, 3:16 PM   #4
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
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?
Cerulean is offline   Reply With Quote
Old Jun 27th, 2005, 3:24 PM   #5
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
XSLT is made for conversions such as this

http://www.w3.org/TR/xslt
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jun 27th, 2005, 9:52 PM   #6
raikkonen
Newbie
 
Join Date: Jun 2005
Posts: 29
Rep Power: 0 raikkonen is on a distinguished road
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.
raikkonen is offline   Reply With Quote
Old Oct 27th, 2005, 9:16 PM   #7
frankish
Hobbyist Programmer
 
frankish's Avatar
 
Join Date: Oct 2005
Location: Ohio
Posts: 177
Rep Power: 0 frankish is an unknown quantity at this point
Do you know C++. There is something on www.sourceforge.net called TinyXML. I have downloaded it but I haven't used it.
frankish is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:52 AM.

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