|
-
Nov 3rd, 2011, 03:05 PM
#1
Thread Starter
Addicted Member
[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!
-
Nov 4th, 2011, 11:19 AM
#2
Thread Starter
Addicted Member
Re: get values from xml elements
-
Nov 4th, 2011, 11:38 AM
#3
Frenzied Member
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.
-
Nov 4th, 2011, 11:56 AM
#4
Thread Starter
Addicted Member
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?
-
Nov 4th, 2011, 02:26 PM
#5
Thread Starter
Addicted Member
Re: get values from xml elements
I've been reading that I need to use a XNamespace, how would I go about doing this?
-
Nov 4th, 2011, 02:45 PM
#6
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|