Solved

Create XML file with some data dynamically and retrieve data from specified XML using ASP

Posted on 2004-04-26
7
427 Views
Last Modified: 2012-06-27
I have 2 tasks to do using ASP.

1. To create XML dynamically with some data and store them in any specified directory in the web server.
2. To retrieve data from any specified xml and display them using HTML elements for better GUI.  

Please answer them with sample code asap. Thanks.
0
Comment
Question by:Justlogin
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:zastil
ID: 10916718
1.

<%

Dim xmlDoc, i
Set xmlDoc = server.CreateObject("msXML.DOMDocument")

Set oRoot = xmlDoc.createElement("Test")
Set xmlDoc.documentElement = oRoot


for i = 1 to 5
     Set oElement = xmlDoc.createElement("NUMBER")
     oRoot.appendChild oElement
     oElement.nodeTypedValue = i
next

xmlDoc.Save("c:\text.xml")
%>
0
 
LVL 3

Accepted Solution

by:
zastil earned 250 total points
ID: 10916749
2.
<%
Dim xmlDoc

Set xmlDoc = server.CreateObject("msXML.DOMDocument")
xmlDoc.async = False
xmlDoc.load("c:\text.xml")

if xmlDoc.parseError.errorcode <> 0 Then
      response.write "Error Code : " & xmlDoc.parseError.errorcode & "<br>"
      response.write "Error Reason : " & xmlDoc.parseError.reason & "<br>"
      response.write "Error Line : " & xmlDoc.parseError.line & "<br>"
      response.write "Error FilePos : " & xmlDoc.parseError.filepos & "<br>"
      response.write "Error Source : " & xmlDoc.parseError.srcText & "<br>"
      response.write "Error URL : " & xmlDoc.parseError.url & "<br>"
end if

Response.Write(aTree(xmlDoc.documentElement))

function aTree(pNode)
      for each atr in pNode.childNodes
            aTree = aTree & atr.text&"<br>"
      next
end function

%>
0
 

Author Comment

by:Justlogin
ID: 10916774
Thanks a lot. please tell me how to get particular value from specified xml in ASP and display them with HTML element for better look & feel.

0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 3

Expert Comment

by:zastil
ID: 10916872
This would return the first node

xmlDoc.documentElement.childnodes(0).text

so this would get the 3rd element and make it a HTML Title.

<h1><%=xmlDoc.documentElement.childnodes(2).text%></h1>

0
 
LVL 3

Expert Comment

by:zastil
ID: 10916944
Bit more detail on attributes

This allows you to find a single node by reference the id in the xml file this example finds id = 2

<%

Dim xmlDoc, i
Set xmlDoc = server.CreateObject("msXML.DOMDocument")

Set oRoot = xmlDoc.createElement("Test")
Set xmlDoc.documentElement = oRoot


for i = 1 to 5
     Set oElement = xmlDoc.createElement("NUMBER")
     
     oElement.nodeTypedValue = "text"&i
     Set objAttrib = xmlDoc.createAttribute("id")
      objAttrib.Text = i
      oElement.Attributes.setNamedItem objAttrib
      oRoot.appendChild oElement

next

xmlDoc.Save("c:\text.xml")


Set xmlDoc = server.CreateObject("msXML.DOMDocument")
xmlDoc.async = False
xmlDoc.load("c:\text.xml")

if xmlDoc.parseError.errorcode <> 0 Then
      response.write "Error Code : " & xmlDoc.parseError.errorcode & "<br>"
      response.write "Error Reason : " & xmlDoc.parseError.reason & "<br>"
      response.write "Error Line : " & xmlDoc.parseError.line & "<br>"
      response.write "Error FilePos : " & xmlDoc.parseError.filepos & "<br>"
      response.write "Error Source : " & xmlDoc.parseError.srcText & "<br>"
      response.write "Error URL : " & xmlDoc.parseError.url & "<br>"
end if

Response.Write(xmlDoc.documentElement.selectSingleNode("NUMBER[@id='2']").text)

%>
0
 

Author Comment

by:Justlogin
ID: 10916963
Ok, i will try this get back to u asap.
0
 

Author Comment

by:Justlogin
ID: 10946698
It works, Thanks.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
API Location, separating out information 10 48
Classic ASP - SQL Server connection problem 5 66
Select record with the most recent date 14 56
Index on a Table 6 15
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question