?
Solved

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

Posted on 2004-04-26
7
Medium Priority
?
459 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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