Bkjia.com instance code: Display xml data in html.
1. Save the following file as myfile. dtd
<! ELEMENT myfile (title, author)> <! ELEMENT title (# PCDATA)> <! ELEMENT author (# PCDATA)> |
2. Create the XML document myfile. xml:
<? Xml version = "1.0" encoding = "GB2312"?> <! DOCTYPE myfile SYSTEM "myfile. dtd"> <Myfile> <Title> XML easy learning manual </title> <Author> ajie </author> </Myfile> |
3.establish the HTML document myfile.html
<Html> <Head> <Script language = "JavaScript" for = "window" event = "onload"> Var xmlDoc = new ActiveXObject ("Microsoft. XMLDOM "); XmlDoc. async = "false "; XmlDoc. load ("myfile. xml "); Nodes = xmlDoc.doc umentElement. childNodes; Title. innerText = nodes. item (0). text; Author. innerText = nodes. item (1). text; </Script> <Title> call XML data www.bkjia.com in HTML </title> </Head> <Body bgcolor = "# FFFFFF"> <B> title: </B> <Span id = "title"> </span> <br> <B> author: </B> <Span id = "author"> </span> <br> </Body> </Html> |