Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Stardeveloper RSS Feed
Newsletter
Enter your email address below to be informed every time a new article is posted at Stardeveloper.com:

You can follow Faisal Khan on Twitter
Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (10)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article

Hosted by Securewebs.com
 
Home : .NET : ASP : Reading XML file with ASP
 

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!

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!


Previous ( 1 Gone )( No Further Pages )

See all comments and questions (post-ad) posted for this tutorial.


Download Associated Files
2000072801.zip

Comments/Questions ( Threads: 2, Comments: 2 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. Required help to navigate in XML document
  2. how to get dynamic data using xml

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed to.

 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.