My problem is that when I execute my stored procedure, the XML data is not saved in my table. I do not receive any error code :((
My xml file:
if you have problem reading my xml file below click here to view it online (more understandable)
<?xml version="1.0"?>
<q:quakeml xmlns="http://quakeml.org/xmlns/bed/1.2" xmlns:catalog="http://anss.org/xmlns/catalog/0.1" xmlns:q="http://quakeml.org/xmlns/quakeml/1.2">
<eventParameters publicID="quakeml:earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.quakeml">
<event catalog:datasource="ak" catalog:eventsource="ak" catalog:eventid="11554973" publicID="quakeml:earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ak11554973.quakeml"><description><type>earthquake name</type><text>5km WSW of North Pole, Alaska</text></description><origin catalog:datasource="ak" catalog:dataid="ak11554973" catalog:eventsource="ak" catalog:eventid="11554973" publicID="quakeml:earthquake.usgs.gov/realtime/product/origin/ak11554973/ak/1429291513635/product.xml"><time><value>2015-04-17T17:13:49.000Z</value></time><longitude><value>-147.4577</value></longitude><latitude><value>64.731</value></latitude><depth><value>10700</value><uncertainty>1300</uncertainty></depth><originUncertainty><horizontalUncertainty>400</horizontalUncertainty><preferredDescription>horizontal uncertainty</preferredDescription></originUncertainty><quality><usedPhaseCount>6</usedPhaseCount><standardError>0.04</standardError></quality><evaluationMode>automatic</evaluationMode><creationInfo><creationTime>2015-04-17T17:25:13.635Z</creationTime><version>1</version></creationInfo></origin><magnitude catalog:datasource="ak" catalog:dataid="ak11554973" catalog:eventsource="ak" catalog:eventid="11554973" publicID="quakeml:earthquake.usgs.gov/realtime/product/origin/ak11554973/ak/1429291513635/product.xml#magnitude"><mag><value>0.7</value></mag><type>ml</type><originID>quakeml:earthquake.usgs.gov/realtime/product/origin/ak11554973/ak/1429291513635/product.xml</originID><evaluationMode>automatic</evaluationMode><creationInfo><creationTime>2015-04-17T17:25:13.635Z</creationTime></creationInfo></magnitude><preferredOriginID>quakeml:earthquake.usgs.gov/realtime/product/origin/ak11554973/ak/1429291513635/product.xml</preferredOriginID><preferredMagnitudeID>quakeml:earthquake.usgs.gov/realtime/product/origin/ak11554973/ak/1429291513635/product.xml#magnitude</preferredMagnitudeID><type>earthquake</type><creationInfo><agencyID>ak</agencyID><creationTime>2015-04-17T17:25:13.635Z</creationTime><version>1</version></creationInfo></event>
<event catalog:datasource="nn" catalog:eventsource="nn" catalog:eventid="00490511" publicID="quakeml:earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nn00490511.quakeml"><description><type>earthquake name</type><text>28km SW of Lovelock, Nevada</text></description><origin catalog:datasource="nn" catalog:dataid="nn00490511" catalog:eventsource="nn" catalog:eventid="00490511" publicID="quakeml:earthquake.usgs.gov/realtime/product/origin/nn00490511/nn/1429291355376/product.xml"><time><value>2015-04-17T17:09:21.386Z</value></time><longitude><value>-118.7333</value></longitude><latitude><value>40.0237</value></latitude><depth><value>0</value><uncertainty>5313.5</uncertainty></depth><originUncertainty><horizontalUncertainty>8118.1</horizontalUncertainty><preferredDescription>horizontal uncertainty</preferredDescription></originUncertainty><quality><usedPhaseCount>13</usedPhaseCount><usedStationCount>11</usedStationCount><standardError>0.1417</standardError><azimuthalGap>245.03</azimuthalGap><minimumDistance>0.591</minimumDistance></quality><evaluationMode>manual</evaluationMode><creationInfo><agencyID>NN</agencyID><creationTime>2015-04-17T17:22:35.376Z</creationTime><version>490511</version></creationInfo></origin><magnitude catalog:datasource="nn" catalog:dataid="nn00490511" catalog:eventsource="nn" catalog:eventid="00490511" publicID="quakeml:earthquake.usgs.gov/realtime/product/origin/nn00490511/nn/1429291355376/product.xml#magnitude"><mag><value>1.95</value><uncertainty>0.23</uncertainty></mag><type>ml</type><stationCount>8</stationCount><originID>quakeml:earthquake.usgs.gov/realtime/product/origin/nn00490511/nn/1429291355376/product.xml</originID><evaluationMode>manual</evaluationMode><creationInfo><agencyID>NN</agencyID><creationTime>2015-04-17T17:22:35.376Z</creationTime></creationInfo></magnitude><preferredOriginID>quakeml:earthquake.usgs.gov/realtime/product/origin/nn00490511/nn/1429291355376/product.xml</preferredOriginID><preferredMagnitudeID>quakeml:earthquake.usgs.gov/realtime/product/origin/nn00490511/nn/1429291355376/product.xml#magnitude</preferredMagnitudeID><type>earthquake</type><creationInfo><agencyID>nn</agencyID><creationTime>2015-04-17T17:22:35.376Z</creationTime><version>490511</version></creationInfo></event>
<creationInfo><creationTime>2015-04-17T17:32:50.000Z</creationTime></creationInfo>
</eventParameters>
</q:quakeml>
My stored procedure:
ALTER PROCEDURE [dbo].[InsertXML]
#xml XML
AS
BEGIN
WITH XMLNAMESPACES ('http://quakeml.org/xmlns/quakeml/1.2' as q,
default 'http://quakeml.org/xmlns/bed/1.2')
INSERT INTO quake_tbl
SELECT
tim.value('(text())[1]','VARCHAR(300)') AS times,
latitud.value('(text())[1]','numeric(18,6)') AS latitude ,
longitud.value('(text())[1]','numeric(18,6)') AS longitude ,
deph.value('(text())[1]','numeric(18,6)') AS depth ,
magnitud.value('(text())[1]','numeric(18,6)') AS magnitude ,
typomag.value('(type/text())[1]','VARCHAR(300)') AS mag_type,
placee.value('(text())[1]','VARCHAR(300)') AS place ,
typo.value('(text())[1]','VARCHAR(300)') AS type
FROM
#xml.nodes('/q:quakeml/eventParameters/event') as TEMPTABLE(quakedetails)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/time/value') AS timess(tim)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/latitude/value') AS lat(latitud)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/longitude/value') AS long(longitud)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/depth/value') AS dep(deph)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('magnitude/mag/value') AS magn(magnitud)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('magnitude/type') AS typmag(typomag)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/description/text') AS plac(placee)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/description/type') AS typ(typo)
END
My vb.net code behind in asp.net:
Imports System.IO
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Partial Class UploadXml
Inherits System.Web.UI.Page
Protected Sub UploadXML(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_upload.Click
Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim filePath As String = Server.MapPath("~/Uploads/") & fileName
FileUpload1.SaveAs(filePath)
Dim xml As String = File.ReadAllText(filePath)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("InsertXML")
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("#xml", xml)
con.Open()
cmd.CommandTimeout = 120
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Sub
End Class
My markup in html:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="UploadXml.aspx.vb" Inherits="UploadXml" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID = "FileUpload1" runat = "server" />
<asp:Button ID="btn_upload" Text="Upload XML" runat="server" />
</div>
</form>
</body>
</html>
When you debug your SELECT statement, it becomes obvious that the last two CROSS APPLY statements don't return any data:
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/description/text') AS plac(placee)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('origin/description/type') AS typ(typo)
So check your XML - somehow that path origin/description doesn't seem to exist.
If you check your XML, you'll see that the <description> node is directly under the <event> node - not under <origin> - so use this:
CROSS APPLY
TEMPTABLE.quakedetails.nodes('description/text') AS plac(placee)
CROSS APPLY
TEMPTABLE.quakedetails.nodes('description/type') AS typ(typo)
and then your query should work.
Update: you could optimize your query by not doing as many CROSS APPLY calls to .nodes() functions - limit yourself to just the <origin> nodes, and then grab the individual bits and pieces inside that node using XPath expression - try this query:
; WITH XMLNAMESPACES ('http://quakeml.org/xmlns/quakeml/1.2' as q,
default 'http://quakeml.org/xmlns/bed/1.2')
SELECT
Times = XOrigin.value('(time/value)[1]', 'varchar(100)'),
Latitude = XOrigin.value('(latitude/value)[1]', 'numeric(18,6)'),
Longitude = XOrigin.value('(longitude/value)[1]', 'numeric(18,6)'),
Depth = XOrigin.value('(depth/value)[1]', 'numeric(18,6)'),
Magnitude = XEvent.value('(magnitude/value)[1]', 'numeric(18,6)'),
Mag_Type = XEvent.value('(magnitude/type/value)[1]', 'varchar(100)'),
Place = XEvent.value('(description/text)[1]', 'varchar(100)'),
[Type] = XEvent.value('(description/type)[1]', 'varchar(100)')
FROM
#xml.nodes('/q:quakeml/eventParameters/event') as XT1(XEvent)
CROSS APPLY
XEvent.nodes('origin') AS XT2(XOrigin)
This is the SELECT only - does that run faster?
Related
I have a table where a column is stored in a xml format so it is possible do display it on other projects with formatted text.
But I need to convert it to a single line without tags.
I have tried to use value() method and nodes(), but didn't quite managed to make it work...
This is the example of the content of the column i want to format.
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css">p {font-family: sans-serif;font-size: 8.25pt;margin: 0px;}</style> </head> <body> <p>VALUE I WANT TO GET </p> </body> </html>
SELECT Id, Description, Value FROM MyTable
Where Value is the column with stored xml..
Is there a way to get the body content without any tags in a single line?
THE COLUMN IS NOT XML TYPE BUT VARCHAR(MAX) TYPE
If your HTML value always same format, please try following scripts together:
Converting HTML into supported format for querying with value () and node()
Declare #x nvarchar (4000) = '<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css">p {font-family: sans-serif;font-size: 8.25pt;margin: 0px;}</style> </head> <body> <p>VALUE I WANT TO GET </p> </body> </html>'
select #x = replace (#x,
'<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ',
''
);
SELECT #x = REPLACE(#x, 'xmlns=', 'xmlns:i=');
--Print #x;
Actual select query on converted XML
select xmldata,
Cast (x2.c.query('data(body/p)') as nvarchar (100)) as HtmlBody
From
(select convert (xml, #x ) as xmldata) as x
cross apply xmldata.nodes('html') as x2(c)
Additional:
Querying direct table, hope this would work if you replace #temp with your table name and column names accordingly
Declare #Temp table (ID bigint, xmlvalue nvarchar(4000) );
Declare #x nvarchar (4000) = '<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css">p {font-family: sans-serif;font-size: 8.25pt;margin: 0px;}</style> </head> <body> <p>VALUE I WANT TO GET </p> </body> </html>';
Insert into #Temp
VALUES (101, #x);
select x.*,
Cast (x2.c.query('data(body/p)') as nvarchar (100)) as HtmlBody
From (
select ID, CAST(REPLACE(
(replace (xmlvalue,
'<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ',
'') ),
'xmlns=',
'xmlns:i='
) AS xml) as xmldata
from #Temp
) as x
CROSS APPLY xmldata.nodes('html') as x2(c)
go
If you think it's difficult to manager in future, create scalar function with same logic - Consider recommendations in terms of performance when using custom scalar functions
You can do something similar to this:
Language is VB.Net.
Dim XMLDoc As New XmlDocument
Dim dt As DataTable = GetData() <-- GetData() is where you load the data using your query
XMLDoc.Load(dt.Rows(0).Item("Value").ToString)
Dim TextThatIWant As string = XMLDoc.SelectSingleNode("/html/body/p").InnerText
Try it like this:
DECLARE #YourValue VARCHAR(MAX)=
'<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css">p {font-family: sans-serif;font-size: 8.25pt;margin: 0px;}</style> </head> <body> <p>VALUE I WANT TO GET </p> </body> </html>';
WITH XMLNAMESPACES(DEFAULT 'http://www.w3.org/1999/xhtml')
SELECT CONVERT(xml,#YourValue,2).value('(/html/body/p/text())[1]','varchar(1000)');
The idea in short:
We can not CAST() the string to XML, due to the <!DOCTYPE>, but we can use CONVERT() with the parameter 2. This will return your string as XML.
Against the XML we can use .value()
As your XML declares a default namespace we declare this namespace using WITH XMLNAMESPACES
Attention: HTML is far not as strict as XML. If you cannot be sure, that your HTML is XHTML actually (which means, that it follows the much stricter rules of XML), it can be dangerous to rely on XML methods. Luckily the namespace points to xhtml...
If not, this might work in all your tests, but break in production at any time...
I am using a servlet(servlet1) via a GET method from httpurlconnection() function in order to get the XML generated by an another servlet(servlet2) connected to a postgreSQL Database.
The XML generated by the servlet2 via the statement:
select query_to_xml('select * from test', true, false, '');
I initialize an httpurlconnection() from servlet1 to servlet2 and I stored in a string "response1" the output like that:
String inputLine;
StringBuffer response1 = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response1.append(inputLine);
}
in.close();
//The output in console
System.out.println(response1.toString());
The XML is stored in the string "response1" as:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="/pro/inc/form.css;jsessionid=D965FA3338EC4E88F6F7AA0B64308446" />
</head>
<body>
<p><alltests_00_with_defects xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<n5>a</n5>
<n4>b</n4>
<n3>c</n3>
<n2>d</n2>
<n1>e</n1>
<row>
<row>
<n5>a</n5>
<n4>b</n4>
<n3>c</n3>
<n2>d</n2>
<n1>e</n1>
<row>
</html>
Until here, it's cool!!
Now, I am looking for a solution that can convert BACK the XML generated to data values.
Any ideas?
Hi I am trying to create an INSERT INTO script in Dreamweaver Command and ASP.
If I use a static value it works fine, but when I try to declare a variable I get the following error message
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Sybase][ODBC Driver][Adaptive Server Anywhere]Primary key for table 'testing'
is not unique
/coding/Untitled-3.asp, line 30
Now the reason it is telling me the primary key is not unique is it is passing a null value, rather than the value of my field. Code below;
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim Command1__product
Command1__product = Request.Form("product")
%>
<!--#include file="Connections/Conn_PSCRM_Demo.asp" -->
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
Set Command1 = Server.CreateObject ("ADODB.Command")
Command1.ActiveConnection = MM_Conn_PSCRM_Demo_STRING
Command1.CommandText = "INSERT INTO testing (prodref) VALUES (?)"
Command1.Parameters.Append Command1.CreateParameter("product", 201, 1, 25, MM_IIF(Request.Form("Field1") , Request.Form("Field1") , Command1__product & ""))
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="form" id="form">
<label for="Field1"></label>
<input name="Field1" type="text" id="Field1" value="33399">
</form>
</body>
</html>
According to my comment - you'll have to check if your form has been posted or your site has just been initially loaded. In your question the code will be executed everytime the site has been loaded - that's why it works when you provide hardcoded values.
Anything like this code will do the trick
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
If Request.Form("SUBMITBUTTON") <> "" then
Dim Command1__product
Command1__product = Request.Form("product")
' all your code goes here!
%>
Bit of a rookie error, I wasn't declaring the form variable.
I have added a Bindings Request.Form and all is working.
I am currently having a problem with some thumbnail images in a classic ASP website. Essentially, I have a database in Microsoft Access that contains three tables: One with the pictures and their info, another that is linked to the pictures table and contains location information and a third table which just has some text for the website.
On the page which is coded below, each image in the database has its corresponding thumbnail printed onto the page. The user can then click on the thumbnail and be taken to the larger image with some associated information.
My problem is that the thumbnails are repeating themselves, up to 11 times.
<% option explicit %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Places</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- #include file="conn.asp" -->
<div id="container">
<!-- #include file="nav.asp" -->
<% dim SQL, info
' 0 1 2 3 4
SQL = "select PicturesTable.id, filename, location, title, description"&_
" from PicturesTable, locationsTable"&_
" where PicturesTable.locationNum = locationsTable.id"&_
" order by locationsTable.id"
set info=conn.execute(SQL)
This is my loop where I think the problem is.
if info.eof then
response.write "No data found."
end if
do until info.eof
response.write "<a href=""images.asp?i=" & info(1) & """>" &_
"<img src=""thumbs/" & info(1) & """></a>"
info.movenext
loop
%>
</div>
<%
conn.close
%>
</body>
</html>
So the problem was in fact that I had designed the database poorly in access and I was repeating the records when they should have been unique. Hence, the repeated images. Deleting the repeated records gave me the solution. Thanks for the help anyway.
Try the following SQL instead; the problem is likely that you need to JOIN the two tables.
SQL = "SELECT PicturesTable.id, filename, location, title, description"&_
" FROM PicturesTable"&_
" LEFT JOIN locationsTable"&_
" ON PicturesTable.locationNum = locationsTable.id"&_
" ORDER BY locationsTable.id
<code>
For Each oXElement In oXDocument.Descendants("searchResult")
sTitle = oXElement.Element("title").Value
Next
</code>
I have also tried:
<code>
For Each oXElement In oXDocument.Elements(searchResults)
sTitle = oXElement.Element("title").Value
Next
</code>
I am having trouble getting a hold of nodes as well as understanding the way you communicate with XDocument nodes.
My Ultimate goal is to create an Ebay Object Model From all Ebay Element's Attributes. For that I need to refer to XML tag somehow - and this is where I would appreciate your advice or sample example that could let me proceed with parsing out this XML response.
Thank you all much for any help.
PS: I have searched for a similar questions and found a few of the same kind but still could not get my parsing to work.
<findItemsByProductResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<ack>Success</ack>
<version>1.12.0</version>
<timestamp>2013-06-02T22:42:04.500Z</timestamp>
<searchResult count="5">
<item>
<itemId>370821427802</itemId>
<title>
Modern Database Management 11E by Hoffer, Ramesh, Topi 11th (Int'l Edition)
</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>2228</categoryId>
<categoryName>Textbooks, Education</categoryName>
</primaryCategory>
<galleryURL>
http://thumbs3.ebaystatic.com/m/meSAqCRbXecSjZjO1833dWQ/140.jpg
</galleryURL>
<viewItemURL>
http://www.ebay.com/itm/Modern-Database-Management-11E-Hoffer-Ramesh-Topi-11th-Intl-Edition-/370821427802?pt=US_Texbook_Education
</viewItemURL>
<productId type="ReferenceID">143649496</productId>
<paymentMethod>PayPal</paymentMethod>
<autoPay>true</autoPay>
<location>Malaysia</location>
<country>MY</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">0.0</shippingServiceCost>
<shippingType>Free</shippingType>
<shipToLocations>Worldwide</shipToLocations>
<expeditedShipping>true</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>1</handlingTime>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">54.07</currentPrice>
<convertedCurrentPrice currencyId="USD">54.07</convertedCurrentPrice>
<sellingState>Active</sellingState>
<timeLeft>P20DT10H47M20S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2013-05-24T09:25:25.000Z</startTime>
<endTime>2013-06-23T09:29:24.000Z</endTime>
<listingType>StoreInventory</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>true</returnsAccepted>
<condition>
<conditionId>1000</conditionId>
<conditionDisplayName>Brand New</conditionDisplayName>
</condition>
<isMultiVariationListing>false</isMultiVariationListing>
<topRatedListing>true</topRatedListing>
</item>
<item>...</item>
<item>...</item>
<item>...</item>
<item>...</item>
</searchResult>
<paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>5</entriesPerPage>
<totalPages>3</totalPages>
<totalEntries>14</totalEntries>
</paginationOutput>
<itemSearchURL>
http://www.ebay.com/ctg/143649496?LH_BIN=1&_ddo=1&_incaucbin=0&_ipg=5&_pgn=1
</itemSearchURL>
</findItemsByProductResponse>
You have to use XNamespace instance when querying your XML:
Dim ns = XNamespace.Get("http://www.ebay.com/marketplace/search/v1/services")
And with that add it to every Descendants, Elements, Element, Attributes, Attributes, etc. calls you make:
For Each oXElement In oXDocument.Descendants(ns + "searchResult")
sTitle = oXElement.Element(ns + "title").Value
Next
For Each oXElement In oXDocument.Elements(ns + searchResults)
sTitle = oXElement.Element(ns + "title").Value
Next
Two things. First, you fell into the trap that catches 90% of the people with problems using LINQ to XML. You forgot the namespace. You can use the following which works in C# or VB:
Dim ns = XNamespace.Get("http://www.ebay.com/marketplace/search/v1/services")
VB Also lets you use a Imports for a namespace just as you import other .Net namespaces at the top of your file. The advantage of this option is that if you have a schema in your project, you get intellisense over the XML structure while building your query.
Imports <xmlns:eb="http://www.ebay.com/marketplace/search/v1/services">
The second issue you have is that the title element is not a direct child of searchResult, but is nested an additional level deeper. Here's a sample leveraging the imports for the namespace. I'm using the VB XML Literals for descendents (...) for contrast with anyone giving you a C# biased answer ;-)
Public Class XmlTest
Public Sub TestXml()
Dim data = <findItemsByProductResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<ack>Success</ack>
<version>1.12.0</version>
<timestamp>2013-06-02T22:42:04.500Z</timestamp>
<searchResult count="5">
<item>
<itemId>370821427802</itemId>
<title>
Modern Database Management 11E by Hoffer, Ramesh, Topi 11th (Int'l Edition)
</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>2228</categoryId>
<categoryName>Textbooks, Education</categoryName>
</primaryCategory>
<galleryURL>
http://thumbs3.ebaystatic.com/m/meSAqCRbXecSjZjO1833dWQ/140.jpg
</galleryURL>
<viewItemURL>
http://www.ebay.com/itm/Modern-Database-Management-11E-Hoffer-Ramesh-Topi-11th-Intl-Edition-/370821427802?pt=US_Texbook_Education
</viewItemURL>
<productId type="ReferenceID">143649496</productId>
<paymentMethod>PayPal</paymentMethod>
<autoPay>true</autoPay>
<location>Malaysia</location>
<country>MY</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">0.0</shippingServiceCost>
<shippingType>Free</shippingType>
<shipToLocations>Worldwide</shipToLocations>
<expeditedShipping>true</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>1</handlingTime>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">54.07</currentPrice>
<convertedCurrentPrice currencyId="USD">54.07</convertedCurrentPrice>
<sellingState>Active</sellingState>
<timeLeft>P20DT10H47M20S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2013-05-24T09:25:25.000Z</startTime>
<endTime>2013-06-23T09:29:24.000Z</endTime>
<listingType>StoreInventory</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>true</returnsAccepted>
<condition>
<conditionId>1000</conditionId>
<conditionDisplayName>Brand New</conditionDisplayName>
</condition>
<isMultiVariationListing>false</isMultiVariationListing>
<topRatedListing>true</topRatedListing>
</item>
<item>...</item>
<item>...</item>
<item>...</item>
<item>...</item>
</searchResult>
<paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>5</entriesPerPage>
<totalPages>3</totalPages>
<totalEntries>14</totalEntries>
</paginationOutput>
</findItemsByProductResponse>
For Each el In data...<eb:searchResult>
Console.WriteLine(el...<eb:title>.Value)
Next
End Sub
End Class