Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


Display an XML document with ASP

 

 

In this example we will create an simple XML file using notepad (or any other text editor for that matter) and then display this in our ASP page .

First start your text editor and enter the following , this will be your XML file .

<?xml version="1.0" encoding="ISO-8859-1"?>
<news>
<item>
<title>new domain name</title>
<link>http://www.beginnersphp.co.uk</link>
<description>we have a new domain name for our PHP site</description>
</item>
</news>

Save this as testing.xml for the purpose of this example .

 

 
 

 

Now we will look at the ASP page to retrieve these values , we want the title , link and the description .

<%
Dim objXML
'create an instance of the MSXML parser
Set objXML = Server.CreateObject("microsoft.XMLDOM")
'load up or XML file , this is stored in the same directory as the script
'in this example
objXML.Load (Server.MapPath("testing.xml"))
'if there are no errors
If objXML.parseError.errorcode = 0 Then
'strTitle is the value of the child node of the <item> element
strTitle = objXML.documentElement.firstChild.firstChild.text
'use the nodeList object , to get the link and description as strings . The index is
'zero based so <link> = 1 and description = 2.
strLink = objXML.documentElement.firstChild.childNodes(1).Text
strDescription = objXML.documentElement.firstChild.childNodes(2).Text
'print out our title
response.Write (strTitle & "<br>")
'print out the URL
Response.Write (strLink & "<br>")
'print the description
Response.Write (strDescription & "<br>")
'if there are errors then we print a message
Else
Response.Write ("There was an error")
End If
'clean up our resources
Set objXML = Nothing
%>


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
copy a file from one location to another(VBScript)
dial a number(VB)
move a directory(C Sharp)
keyboard info using wmi(VB)
displays a list of My Computer locations(VBScript)
delete files on a floppy disk(VB)
Display the dimensions of an image(PHP)
populate a select menu from MySQL(PHP)

    




Copyright © 2003 by programmershelp.co.uk