Solved

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

Posted on 2004-04-26
7
451 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

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…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

707 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