Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3278314
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:28:03+00:00 2026-05-17T19:28:03+00:00

I am trying to read xml nodes values from lastfm web service that look

  • 0

I am trying to read xml nodes values from lastfm web service that look like this:

<lfm status="ok"> 
<results for="stinkfist" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"> 
<opensearch:Query role="request" searchTerms="stinkfist" startPage="1" /> 
<opensearch:totalResults>188</opensearch:totalResults> 
<opensearch:startIndex>0</opensearch:startIndex> 
<opensearch:itemsPerPage>1</opensearch:itemsPerPage> 
<trackmatches> 
<track> 
    <name>Stinkfist</name> 
    <artist>Tool</artist> 
    <url>http://www.last.fm/music/Tool/_/Stinkfist</url> 
    <streamable fulltrack="0">1</streamable> 
    <listeners>290583</listeners> 
         <image size="small">http://userserve-ak.last.fm/serve/34s/24508457.jpg</image> 
    <image size="medium">http://userserve-ak.last.fm/serve/64s/24508457.jpg</image> 
    <image size="large">http://userserve-ak.last.fm/serve/126/24508457.jpg</image> 
    <image size="extralarge">http://userserve-ak.last.fm/serve/300x300/24508457.jpg</image> 
 <mbid></mbid> 
</track> 
</trackmatches> 
</results>
</lfm>

After searching here and on the web for examples i found a way that should work:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim doc As XmlDocument
    Dim ns As XmlNamespaceManager
    Dim nodes As XmlNodeList
    doc = New XmlDocument()
    doc.Load("http://ws.audioscrobbler.com/2.0/?method=track.search&limit=1&track=stinkfist&artist=tool&api_key=b25b959554ed76058ac220b7b2e0a026")
    ns = New XmlNamespaceManager(doc.NameTable)
    ns.AddNamespace("lastfm", "http://a9.com/-/spec/opensearch/1.1/")
    nodes = doc.SelectNodes("lastfm:results/lastfm:trackmatches/lastfm:track", ns)
    Dim str As String = String.Empty
    For Each node As XmlNode In nodes
        str += node.Attributes("name").InnerText
        str += node.Attributes("artist").InnerText
        str += node.Attributes("url").InnerText
        str += node.Attributes("listeners").InnerText
    Next

    Response.Write(str)

End Sub

But when i run the page i get no results the page is empty…
what am i doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:28:04+00:00Added an answer on May 17, 2026 at 7:28 pm

    There are a couple of issues that I see.

    First, you don’t need to add the namespace lastfm only opensearch (if you need to access those elements).

    So this line:

    ns.AddNamespace("lastfm", "http://a9.com/-/spec/opensearch/1.1/")
    

    Would become:

    ns.AddNamespace("opensearch", "http://a9.com/-/spec/opensearch/1.1/")
    

    If you needed to access the opensearch elements you would then use it like:

    doc.SelectSingleNode("lfm/results/opensearch:totalResults", ns).InnerText
    

    To select the track nodes your XPath query should be:

    nodes = doc.SelectNodes("/lfm/results/trackmatches/track")
    

    The track nodes do not have attributes, so node.Attributes("name").InnerText will not work. Rather, they have child elements (nodes), so to get those values you can do:

    node.SelectSingleNode("name").InnerText
    

    or even shorter syntax

    node("name").InnerText
    

    Putting it all together, your program would resemble the following:

    Dim doc As XmlDocument
    Dim ns As XmlNamespaceManager
    Dim nodes As XmlNodeList
    
    doc = New XmlDocument()
    doc.Load("http://ws.audioscrobbler.com/2.0/?method=track.search&track=Believe&api_key=b25b959554ed76058ac220b7b2e0a026")
    ns = New XmlNamespaceManager(doc.NameTable)
    ns.AddNamespace("opensearch", "http://a9.com/-/spec/opensearch/1.1/")
    nodes = doc.SelectNodes("/lfm/results/trackmatches/track")
    Dim str As String = String.Empty
    For Each node As XmlNode In nodes
        str += node.SelectSingleNode("name").InnerText
        str += node.SelectSingleNode("artist").InnerText
        str += node.SelectSingleNode("url").InnerText
        str += node.SelectSingleNode("listeners").InnerText
    Next
    

    Lastly, MSDN has very good examples of using XPath and XmlDocument, which you may find useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.