Hi!
I have translated some code from C# to VB. I found the code here
http://www.codeproject.com/KB/webservices/FaisonMusicExplorer1.aspx?msg=4036510#xx4036510xx
I try to retrieve the artist ID from the musicbrainz server, but i get an error when i use my translated code in VB.
When I look at the string value xpath in C# it holds the value "
//mb:artist[mb:name="The Beatles\]". After that it retrieves the artist ID without any problem.
Now, when I try to do the same in VB it does not retrieve the artist ID.
The first code-block is the one I found, the second is my translation of the first code-block. I can't see what i'm doing wrong...
public static string FindArtistId(string name)
{
try
{
string uri = string.Format("http://musicbrainz.org/ws/1/artist/?query={0}&type=xml", name);
XPathDocument doc = new XPathDocument(uri);
XPathNavigator nav = doc.CreateNavigator();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
nsmgr.AddNamespace("mb", "http://musicbrainz.org/ns/mmd-1.0#");
string xpath = string.Format("//mb:artist[mb:name=\"{0}\"]", name);
XPathNodeIterator ni = nav.Select(xpath, nsmgr);
if (!ni.MoveNext()) return null;
XPathNavigator current = ni.Current;
return current.GetAttribute("id", nsmgr.DefaultNamespace);
}
catch (WebException wex)
{
MessageBox.Show(string.Format("A communication error occurred ({0}). The MusicBrainz server might be down.", wex.Status), "Couldn't resolve artist name");
return null;
}
catch (Exception ex)
{
MessageBox.Show(string.Format("An error occurred ({0}). The error may have been caused by bad data from the MusicBrainz server.", ex.Message), "Couldn't resolve artist name");
return null;
}
}
Public Function FindArtistId(ByVal name As String) As String
Try
Dim uri As String = String.Format("http://musicbrainz.org/ws/1/artist/?query={0}&type=xml", name)
Dim doc As XPathDocument = New XPathDocument(uri)
Dim nav As XPathNavigator = doc.CreateNavigator()
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(nav.NameTable)
nsmgr.AddNamespace("mb", "http://musicbrainz.org/ns/mmd-1.0#")
Dim xpath As String = String.Format("//mb:artist[mb:name=""{0}""]", name)
Dim ni As XPathNodeIterator = nav.Select(xpath, nsmgr)
If ni.MoveNext() Then Return Nothing
Dim current As XPathNavigator = ni.Current
Return current.GetAttribute("id", nsmgr.DefaultNamespace)
Catch wex As WebException
MessageBox.Show(String.Format("A communication error occurred ({0}). The MusicBrainz server might be down.", wex.Status), "Couldn't resolve artist name")
Return Nothing
Catch ex As Exception
MessageBox.Show(String.Format("An error occurred ({0}). The error may have been caused by bad data from the MusicBrainz server.", ex.Message), "Couldn't resolve artist name")
Return Nothing
End Try
End Function