ASP Classic - Read XML File inner content

Wayne Barron
Wayne Barron used Ask the Experts™
on
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/>"  
Next 

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="http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom">
  <entry>
    <media:group>
      <media:title>Title Here</media:title>
      <media:description>information here</media:description>
      <media:community>
        <media:starRating count="92070"/>
        <media:statistics views="2151299"/>
      </media:community>
    </media:group>
  </entry>

Open in new window


Thanks, All
Carrzkiss
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shooting in pitch black dark!

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

Count = Rating.Attributes[0].text
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
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

Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
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.

://www.experts-exchange.com/questions/28354861/receive-XML-request-and-return-it-using-classic-ASP.html
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

You should set the SelectionNamespaces property first:
objXML.setProperty "SelectionNamespaces", "xmlns:media='http://search.yahoo.com/mrss/'"

Open in new window

Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
@Nitin
>> 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
-------------------------------------------^

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

@zc2
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.

@Scott.
I will check out the link you provided.
Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
@Scott.
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.
Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
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.
Wayne
Shooting in pitch black dark!

NEVER EVER do I say such things to others. I say it to myself.
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
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.
Wayne BarronAuthor, Web Developer
Top Expert 2009

Author

Commented:
@Nitin.
No problem, I was able to use your code, with some tweaking.

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial