Link to home
Start Free TrialLog in
Avatar of fox_statton
fox_statton

asked on

XML Dom GetAttribute in ASP?

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
ASKER CERTIFIED SOLUTION
Avatar of topcat_uk
topcat_uk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fox_statton
fox_statton

ASKER

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

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<
Got it working, prob was in the xml!
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.