![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Posts: 29
Rep Power: 0
![]() |
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 ..
|
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
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> |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2005
Posts: 29
Rep Power: 0
![]() |
hmmm thanks man.. i dont quite know what is python script. could you tell me? thanks in advance.
|
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
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? |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
__________________
"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 |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Jun 2005
Posts: 29
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Oct 2005
Location: Ohio
Posts: 177
Rep Power: 0
![]() |
Do you know C++. There is something on www.sourceforge.net called TinyXML. I have downloaded it but I haven't used it.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|