Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

XML Tutorial
XML Introduction
XML How to use
XML Syntax
XML Elements
XML Attributes
XML Validation
XML Validator
XML Browsers
XML Viewing
XML CSS
XML XSL
XML Data Island
XML Parser
XML in Real Life
XML Namespaces
XML CDATA
XML Encoding
XML Server
XML Application
XML HTTP Request
XML Save Data
XML Behaviors
XML Technologies
XML Editors
XML Summary
XML as Data Source

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


XML as Data Source

Previoushome Next



After this tutorial, you will be able to manipulate and play with XML Data files in the same way as you do with MS Access. In addition to that, there are certain advantages of using XML, over MS Access.


A D V E R T I S E M E N T



Retrieving XML using ASP

F or most of the net based organizations, the data stored in their databases are their sole property. How this data can be organized more effectively and efficiently using XML, is the theme of this article.

When you create a database in MS Access, even if it is empty, it takes a lot of space just for structure. Right ? Why waste this much space just for structure when you can store information about at least a hundred members of your site in the same space. When you store data as XML, it is stored in the form of a simple text file with the extension .XML, along with a few tags. For the time being, I will not go in the detailed theory of explaining the intricacies of XML, but rather concentrate on how to access and manipulate it using ASP.

Before we begin, what all is required for your web server to be able to serve XML. For the Server Side XML Processing, IE 5.0+ must be installed on the server. This is because we need XML DOM (XML Document Object Model), which is basically an XML Parser, which is provided as a component of IE5.

Now we are ready to write our scripts. We need two things.

  • Data Source
  • ASP Script to manipulate the data.

Let us first create a data source. Suppose we want to maintain a resource repository in which we want to include a brief description of the resource, its link on the web and its link text. The Sample XML data source for this can be:

(Contents of File Resource.XML)

<?xml version="1.0" ?> 
<Resource_Repository>
    <Resource>
        <text>
            This program allows you to encrypt your HTML Source Codes
            so that no one can steal and Copy Paste them in their own site.
        </text> 
        <link>
            <url>
                ftp://ftp.cedium.net/internet/htmlcrypt/encryptHTML.exe
            </url> 
            <linetext>
                HTML Source Code Encryption
            </linetext> 
        </link>
        <Size>
               736 KB
        </Size> 
    </Resource>

    <Resource>
        <text>
            DOS Based Eliza Program. Eliza is a Computer program that can talk to you
            like a human being. Makes use of Artificial Intelligence.
        </text> 
        <link>
            <url>
                http://hps.elte.hu/~gk/Eliza/ELIZA.EXE
            </url> 
            <linetext>
                Eliza Chatterbot
            </linetext> 
        </link>
        <Size>
                36 KB
        </Size> 
    </Resource>
</Resource_Repository>

Now we write a script to access this data and display it on the web page. I result will be generated in a very simple format, to make the ASP Code simple to understand.

To begin with, we need to create an XML DOM object on the server. This can be done with a line as simple as :

<% Set objXML = Server.CreateObject("Microsoft.XMLDOM") %>

Now we need to give the path of our data source. So add the following line to the code:

<% 
objXML.Load (Server.MapPath("Resource.xml"))

If objXML.parseError.errorCode <> 0 Then
Response.Write "<p><font color=red>Error loading the Resource file.</font></p>"
Response.End
End If
%>

If the XML DOM Parser throws any error, then we catch that and display the error message.

We want to display the list of all the resources in the file Resource.xml. We know that the resources are enclosed within <Resource> tag. So, the next step is to create a list of all the objects under the tag <Resource>.

<%
Set objLst = objXML.getElementsByTagName("Resource")
%>

The Length property of object list indicates the number of items in the list. For example, in our example of Resource.xml, there are two records under the <Resource> tag. So, objLst.Length shows the value 2, when displayed.

<%
Response.write "There are " & objLst.Length & " resources on this site."
%>

This is quite interesting upto now. What about accessing individual sub-items ? Suppose we just want to display the URLs of all the resources in our 'database', how can we do that ?

Create one more object, now referring to the items inside the object list. The sub-items can be accessed by using childNodes(index). See this code for further understanding :

<% 
' for each resource in the list
For i = 0 To objLst.Length - 1 

Set subLst = objLst.item(i)

Response.write "<P>" & vbcrlf 
Response.Write "<a href='" & subLst.childNodes(1).childNodes(0).Text & "'>" _
& subLst.childNodes(1).childNodes(0).Text & "</a>" 
Next
%>

A careful look at the structure of the XML document that we had created earlier reveals that <URL> is inside <Link> which is second element of the <Resource> (first being <text>). If we start our indexing from 0 (Zero), then <Link> is the first element of <Resource> and <URL> is the Zeroeth element inside <Link>. That's why I have written the line:

subLst.childNodes(1).childNodes(0).Text

which is nothing but <URL>. Re-read the previous paragraph if you are still not clear and I am sure you will get it soon.

So, the final source code of the ASP file we have created for displaying the URL of all the resources in our database is:

<% 
' creating an object of XMLDOM
Set objXML = Server.CreateObject("Microsoft.XMLDOM") 

' Locating our XML database
objXML.Load (Server.MapPath("Resource.xml"))

' checking for error
If objXML.parseError.errorCode <> 0 Then
Response.Write "<p><font color=red>Error loading the Resource file.</font></p>"
Response.End
End If

' referring to Resource 
Set objLst = objXML.getElementsByTagName("Resource")
Response.write "There are " & objLst.Length & " resources on this site ."

' for each resource
For i = 0 To objLst.Length - 1 

' refer to sub-item
Set subLst = objLst.item(i)

'display the URL
Response.Write "<a href='" & subLst.childNodes(1).childNodes(0).Text & "'>" _ 
& subLst.childNodes(1).childNodes(0).Text & "</a>"
Next 
%>

Of course, you would need to add all those formatting HTML tags to make this list more attractive. But the core remains the same.

Conclusion:

In this article, we learned how to retrieve the 'records' from XML 'database'. For complete Database related operations, we must know how to insert, update and delete the records from the Scripts. In the next article, we will see how to perform these operations as well.

Written by Amit Mathur, India on 6th Dec., 2002

See the article

Be the first one to comment on this page.




  XML Tutorial eBooks
More Links » »
 
 XML Tutorial FAQs
More Links » »
 
 XML Tutorial Interview Questions
More Links » »
 
 XML Tutorial Articles
More Links » »
 
 XML Tutorial News
More Links » »
 
 XML Tutorial Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: xml tutorial, xml editor, xml file, xml document, xml schema, xml spy, xml parser, open xml document file format, free rss feeds xml, xml feed

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.