|
Next we create four variables to hold the data which we retrieve from the XML file.
xml.documentElement takes us to the 'main' tag of our XML file.
Then .childNodes(n) takes us to that child node within the super
node which in our case is the 'main' node. Since there are 4 child nodes within the 'main'
node we can use values from 0 - 3 to get to the node we want. Once we have got to the node
we want, we can use .text to retrieve it's value as text.
In the rest of the code we show the retrieved values which we got from the page.xml
file.
Running 'showxml.asp' page
Put 'page.xml' and 'showxml.asp' pages in the same directory where you can run
ASP pages. For example, you can put both of them in the c:/inetpub/wwwroot directory.
Then use http://127.0.0.1/showxml.asp to see it running. Otherwise add directory path to
the URL depending on where you have kept it e.g. if you have kept these pages in
c:/inetpub/wwwroot/xml/ directory then use http://127.0.0.1/xml/showxml.asp page to view
it.
Creating XML Files
Always add <?xml version="1.0"?> on top of your XML page. Then enclose
all elements and their sub-elements inside a main element, you can name this main
element whatever you want but in our example we named it 'main'.
Every starting tag must have an end tag. Elements may or may not contain attributes,
in our example we did not make use of attributes to keep things simple.
If you want to write HTML code inside an XML element, then enclose that HTML code
within <![CDATA[..............]]> markup tags.
Reading XML Files
Set .sync to False to speed up
the retrieval of data from XML page.
Happy learning!
|