[RESOLVED] get values from xml elements
Here's a portion of my XML string.
<OpenSearchDescription>
<opensearch:Query searchTerms="Star Wars"/>
<opensearch:totalResults>18</opensearch:totalResults>
Here's my code:
Code:
Dim xml As String = tmdb_.Movie_search(tbTitle.Text, cbYear.Text)
Dim xdoc As XDocument = XDocument.Parse(xml)
lbResults.Text = xdoc.Element("totalResults").Value.ToString
The line "Dim xml As String = tmdb_.Movie_search(tbTitle.Text, cbYear.Text)" produces a string with the entire xml return. How do I go about setting lbResult.Text to "18" or the value of "<opensearch:totalResults>"
Thanks!
Re: get values from xml elements
Re: get values from xml elements
I think you need to specify the full Xpath. Maybe something like:
Code:
lbResults.Text = xdoc.Element("OpenSearchDescription").Element("opensearch:totalResults").Value
And you dont need the .ToString at the end as .Value is already a string.
Re: get values from xml elements
Thanks for the reply, but running it I get the following error.
"The ':' character, hexadecimal value 0x3A, cannot be included in a name."
Any thoughts?
Re: get values from xml elements
I've been reading that I need to use a XNamespace, how would I go about doing this?
Re: get values from xml elements
Woohoo I did it.
Code:
Imports <xmlns="http://a9.com/-/spec/opensearch/1.1/">
In the function:
Dim xname As XNamespace = "http://a9.com/-/spec/opensearch/1.1/"
lbResults.Text = xdoc.Element("OpenSearchDescription").Descendants(xname + "totalResults").Value