In the past I went by some ms articles to figure out how to load and parse some xml for 'toptracks' script, and that works fine for a few of the last.fm feeds, however there are some that don't use the same structure and I am having difficulties figuring out how/which properties/methods to use for the xmldoc object..
For example:
- Code: Select all
For Each Ele In LastFMXML.getElementsByTagName("name")
TrackTitle = Ele.ChildNodes.Item(0).Text
this xml code extracts the track title based on the 'name' element from the following feeds:
artist/similar.xml
- Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
- <similarartists artist="Metallica" streamable="1" picture="http://userserve-ak.last.fm/serve/160/199543.jpg" mbid="65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab">
- <artist>
<name>Iron Maiden</name>
<mbid>ca891d65-d9b0-4258-89f7-e6ba29d83767</mbid>
<match>100</match>
<url>http://www.last.fm/music/Iron+Maiden</url>
<image_small>http://userserve-ak.last.fm/serve/50/243479.jpg</image_small>
<image>http://userserve-ak.last.fm/serve/160/243479.jpg</image>
<streamable>1</streamable>
</artist>
- <artist>
<name>Megadeth</name>
<mbid>a9044915-8be3-4c7e-b11f-9e2d2ea0a91e</mbid>
<match>97.69</match>
<url>http://www.last.fm/music/Megadeth</url>
<image_small>http://userserve-ak.last.fm/serve/50/369941.jpg</image_small>
<image>http://userserve-ak.last.fm/serve/160/369941.jpg</image>
<streamable>1</streamable>
</artist>
artist/toptracks.xml
- Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
- <mostknowntracks artist="Metallica">
- <track>
<name>Nothing Else Matters</name>
<mbid />
<reach>80023</reach>
<url>http://www.last.fm/music/Metallica/_/Nothing+Else+Matters</url>
</track>
- <track>
<name>Enter Sandman</name>
<mbid />
<reach>77111</reach>
<url>http://www.last.fm/music/Metallica/_/Enter+Sandman</url>
</track>
- <track>
<name>One</name>
<mbid />
<reach>66629</reach>
<url>http://www.last.fm/music/Metallica/_/One</url>
</track>
However other important feeds use a different structure and I can't figure out the proper way to extract the needed fields.. namely 'track name' and 'artist name'..
tag/toptracks.xml
- Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
- <tag tag="rock" count="1598230">
- <track name="Once Upon a Time" count="1077" streamable="no">
- <artist name="Frank Zappa">
<mbid>e20747e7-55a4-452e-8766-7b985585082d</mbid>
<url>http://www.last.fm/music/Frank+Zappa</url>
</artist>
<url>http://www.last.fm/music/Frank+Zappa/_/Once+Upon+a+Time</url>
<thumbnail>http://ec1.images-amazon.com/images/P/B0000009TN.01._SCMZZZZZZZ_.jpg</thumbnail>
<image>http://ec1.images-amazon.com/images/P/B0000009TN.01._SCMZZZZZZZ_.jpg</image>
</track>
- <track name="Painting the Town Blue" count="862" streamable="no">
- <artist name="X">
<mbid>ddd553d4-977e-416c-8f57-e4b72c0fc746</mbid>
<url>http://www.last.fm/music/X</url>
</artist>
<url>http://www.last.fm/music/X/_/Painting+the+Town+Blue</url>
<thumbnail>http://images.amazon.com/images/P/B000005IRQ.01._SCMZZZZZZZ_.jpg</thumbnail>
<image>http://images.amazon.com/images/P/B000005IRQ.01._SCMZZZZZZZ_.jpg</image>
</track>
similar tracks is again different where artist/name and track/name are different elements.
track/similartracks.xml
- Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
- <similartracks>
- <track>
- <artist>
<name>Iron Maiden</name>
<url>http://www.last.fm/music/Iron+Maiden</url>
</artist>
<name>Run to the Hills</name>
<match>24.84</match>
<url>http://www.last.fm/music/Iron+Maiden/_/Run+to+the+Hills</url>
<streamable>1</streamable>
</track>
- <track>
- <artist>
<name>Iron Maiden</name>
<url>http://www.last.fm/music/Iron+Maiden</url>
</artist>
<name>The Number of the Beast</name>
<match>22.84</match>
<url>http://www.last.fm/music/Iron+Maiden/_/The+Number+of+the+Beast</url>
<streamable>1</streamable>
</track>
btw the last.fm feeds are listed @ the audioscrobbler site, so you can there is some variance between the structures of the various feeds.. this makes it difficult to have one single function be able to parse them effectively.. most of the types will require a custom parser to extract the relevant fields..
Any help or pointers to good websites would be appreciated... I've been googling around and haven't really found some examples I can use, or been able to get it through my head how to walk the xml to get the needed info.



