Avatar of Wayne Barron
Wayne Barron
Flag 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/>"  
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
ASPXML

Avatar of undefined
Last Comment
Wayne Barron

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Nitin Sontakke

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mccarl

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 Fell

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.

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

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

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Wayne Barron

ASKER
@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 Barron

ASKER
@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 Barron

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Nitin Sontakke

Shooting in pitch black dark!

NEVER EVER do I say such things to others. I say it to myself.
mccarl

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 Barron

ASKER
@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.
Your help has saved me hundreds of hours of internet surfing.
fblack61