Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

ASP Classic - Read XML File inner content

Hello, All;

Could someone please assist me in reading the inner parts of these nodes.
I can get all the other data, just not the count and views.

ASP Script
   Set objXML = Server.CreateObject("MSXML2.DOMDocument.3.0")
   objXML.async = False
objXML.Load (Server.MapPath("test.xml"))

For Each xmlProduct In objXML.documentElement.selectNodes("/feed/entry")
     theTitle = xmlProduct.selectSingleNode("media:group/media:title").text
     theDescr = xmlProduct.selectSingleNode("media:group/media:description").text 
     Rating = xmlProduct.selectSingleNode("media:group/media:community/media:starRating[@count]").text 
     statistics = xmlProduct.selectSingleNode("media:group/media:community/media:statistics").text
	 Response.Write "<strong>"&Server.HTMLEncode(theTitle) & "</strong><br>"
	 Response.Write "<strong>"&Server.HTMLEncode(thedescr) & "</strong><br>"
	 Response.Write "<strong>"&Server.HTMLEncode(Rating) & "</strong><br>"   
	 Response.Write "<strong>"&Server.HTMLEncode(statistics) & "</strong><br><hr/>"  

Set objXML = Nothing  

Open in new window

XML Script
The two area's that I need to get the values from are
        <media:starRating count="92070"/>   (The count)
        <media:statistics views="2151299"/>  (The Views)
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:media="" xmlns="">
      <media:title>Title Here</media:title>
      <media:description>information here</media:description>
        <media:starRating count="92070"/>
        <media:statistics views="2151299"/>

Open in new window

Thanks, All
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try taking the square brackets out of the XPath expression...

     Rating = xmlProduct.selectSingleNode("media:group/media:community/media:starRating@count").text 

Open in new window

I have a bunch of previous examples from similar questions here on ee.  See if my answer by example helps point you in the right direction.

You should set the SelectionNamespaces property first:
objXML.setProperty "SelectionNamespaces", "xmlns:media=''"

Open in new window

Avatar of Wayne Barron


>> Shooting in pitch black dark!
What do you mean? I provided all the source code, for you to compile together in order to give a working example for your answer.
So, why would you come in and say: Shooting in pitch black dark.
The only whay that would be true, is if I would have provided just information and no source code.
I tested out your code as well, and it gave me an error.

Expected end of statement
/test/asp/test.asp, line 10
sCount = Rating.GetAttribute[0].text

Your code gives me the following error.
Expected token 'eof' found '@'. media:group/media:community/media:starRating-->@<--count

That is fine, in the actual project, that it already set.
I am wanting to find out how to get the COUNT and the VIEWS at this moment.

I will check out the link you provided.
I looked at your code, and could not make sense of it. Sorry.

I tried this.

 set Rating = xmlProduct.selectSingleNode("media:group/media:community/media:starRating")
  sCount = Rating.Item(0).getAttribute("count")

It gives me the following error.
Object doesn't support this property or method: 'Rating.Item'

So, with the newly found knowledge from trying that.
I took the example from Nitin
And change the [] to ()
sCount = Rating.Attributes(0).text

And it worked.
I am good to go on this one.
I have to add one last thing here.
I had to SET the Variable.

     set Rating = xmlProduct.selectSingleNode("media:group/media:community/media:starRating")
	 sCount = Rating.Attributes(0).text
     set Stats = xmlProduct.selectSingleNode("media:group/media:community/media:statistics")
	 sStats = Stats.Attributes(0).text
	 Response.Write "<strong>"&Server.HTMLEncode(sCount) & "</strong><br>"   
	 Response.Write "<strong>"&Server.HTMLEncode(sStats) & "</strong><br><hr/>"  

Open in new window

Have a good one all.
Shooting in pitch black dark!

NEVER EVER do I say such things to others. I say it to myself.
Sorry, I was not on my game before, you need a forward slash too...

     Rating = xmlProduct.selectSingleNode("media:group/media:community/media:starRating/@count").text 

Open in new window

Be careful with the code that you have posted, in case the there can be more than one attribute on the starRating element and "count" is not the first one.
No problem, I was able to use your code, with some tweaking.

I will test later on.
Right now, I have a working code.