Solved

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

Posted on 2004-04-26
7
410 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now