Solved

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

Posted on 2004-04-26
7
445 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 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
Industry Leaders: 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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