Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XML Dom GetAttribute in ASP?

Posted on 2003-03-04
5
Medium Priority
?
2,094 Views
Last Modified: 2013-11-19
Hi all, Ive being trying to do something relatively simple but forwhatever reason its not working.

Ive got the following XML file and want to get the attribute "time" out of it,

  <?xml version="1.0" ?>
- <note time="12:03:46">
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
  </note>

I was using the following code but it doesnt work...

<%

Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
'load xml file
xmlDoc.Load(Server.MapPath("sys.xml"))

set strX=xmlDoc.getElementsByTagName("item")
set strY=strX.item(0).getAttribute("id")

response.write strY

%>

Thanks!

Alicia
0
Comment
Question by:fox_statton
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
topcat_uk earned 200 total points
ID: 8063529
Hi Alicia,

You need to select the element then the attribute.
<%

Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
'load xml file
xmlDoc.Load(Server.MapPath("sys.xml"))

Set strx = xmldoc.getElementsByTagName("note")
stry = strx.Item(0).getAttribute("time")

response.write strY

%>
0
 

Author Comment

by:fox_statton
ID: 8063737
Hi, i get the following error when I load the page:

Microsoft VBScript runtime error '800a01a8'

Object required: 'strx.Item(...)'

/sf27621/menu4/mock4/attribute.asp, line 10

0
 
LVL 9

Expert Comment

by:sparkplug
ID: 8063875
Hi,

Try this:

Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
'load xml file
If Not xmlDoc.Load(Server.MapPath("sys.xml")) Then
   Response.write "Error parsing XML: " & xmlDoc.parseError.reason
End If

set oTimeAttr=xmlDoc.selectSingleNode("/note/@time")
sTime=oTimeAttr.nodeValue

response.write sTime

>S'Plug<
0
 

Author Comment

by:fox_statton
ID: 8072623
Got it working, prob was in the xml!
0
 
LVL 1

Expert Comment

by:topcat_uk
ID: 8072717
Ha Ha.

If I could have a pound for everytime I have done that, I would be playing golf right now, or perhaps on a beach somewhere hot.

Anyway, glad it's working.
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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

580 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