?
Solved

XML Dom GetAttribute in ASP?

Posted on 2003-03-04
5
Medium Priority
?
2,061 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
[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
  • 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

801 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