Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Thursday, March 22, 2012

Error in X-Path Query

I am new to XML in SQL Server and X-Path Query

Recently I have done the following virtual lab in techNet site

SQL Server 2005 XML Capabilities

The following query is worked fine in the lab

SELECTTOP 10 Demographics.query('declare default element namespace=

"http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"

/IndividualSurvey/YearlyIncome')

FROM Sales.Individual

But later I installed SQL Server Express in my system and also the Express Manager CTP

but i am getting the following error if I execute the above query in my system

Msg 9317, Level 16, State 1, Line 1

XQuery [Sales.Individual.Demographics.query()]: Syntax error near '=', expected string literal.

Check ou this link: http://tinyurl.com/avqxx

Check out this syntax. I think your syntax is wrong and are missing a ref to the namespace and a ' ; '.

I.e

SELECT MyXml.query('

declare namespace s="http://myns/mydemoschema";

/s:root/s:product[@.s:id="304"]/s:name')FROM MyTable

notice the ; indeclare namespace s="http://myns/mydemoschema";

|||i think the name space is required when we are assigning the declared name space to a reference such as "s=" in the above example|||take default element out too.|||

Finally It is solved

I found the problem from another forum athttp://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=145&messageid=248323

Here is the answer given by Veteran

To declare default namespace, there is no "=" after namespace keyword. And there is a ";" after the namespace string. The following query works:

SELECTTOP 10 Demographics.query('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";

/IndividualSurvey/YearlyIncome')

FROM Sales.Individual

Error in X-Path Query

I am new to XML in SQL Server and X-Path Query

Recently I have done the following virtual lab in techNet site

SQL Server 2005 XML Capabilities

The following query is worked fine in the lab

SELECT TOP 10 Demographics.query('declare default element namespace=

"http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"

/IndividualSurvey/YearlyIncome')

FROM Sales.Individual

But later I installed SQL Server Express in my system and also the Express Manager CTP

but i am getting the following error if I execute the above query in my system

Msg 9317, Level 16, State 1, Line 1

XQuery [Sales.Individual.Demographics.query()]: Syntax error near '=', expected string literal.

The correct syntax for the XQuery expression is below:

SELECT TOP 10 Demographics.query('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
/IndividualSurvey/YearlyIncome')
FROM Sales.Individual

sql

Wednesday, March 7, 2012

Error in Executing Bulk Load using SQLXML 4.0

I have a number of apps which do xml bulk load using sqlxml 4.0. But, in on
e
program when I attempt to execute the following
SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class bulkLoadObject = new
SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class();
I get this error raised.
"Unable to cast COM object of type 'SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class'
to interface type 'SQLXMLBULKLOADLib.ISQLXMLBulkLoad4'. This operation faile
d
because the QueryInterface call on the COM component for the interface with
IID '{88465BA7-AEEE-49A1-9499-4416287A0160}' failed due to the following
error: No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE))."
While in another app the same statement executes with no problems.
I have no compile errors in the offending program. I have dropped the
reference and re-added a couple of times.
Does anyone have any insight?Could this be something related to the interop DLL in the GAC? What
happens when you refresh it?|||All the other apps that use SQLXML 4.0 bulk load on that machine have no
problems.|||Hello,
This is usually due to the fact that you are missing [STAThread] declaration
like in:
[STAThread]
static void Main()
Hope this helps,
Monica Frintu
"AlanS" wrote:

> I have a number of apps which do xml bulk load using sqlxml 4.0. But, in
one
> program when I attempt to execute the following
> SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class bulkLoadObject = new
> SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class();
> I get this error raised.
> "Unable to cast COM object of type 'SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class
'
> to interface type 'SQLXMLBULKLOADLib.ISQLXMLBulkLoad4'. This operation fai
led
> because the QueryInterface call on the COM component for the interface wit
h
> IID '{88465BA7-AEEE-49A1-9499-4416287A0160}' failed due to the following
> error: No such interface supported (Exception from HRESULT: 0x80004002
> (E_NOINTERFACE))."
> While in another app the same statement executes with no problems.
> I have no compile errors in the offending program. I have dropped the
> reference and re-added a couple of times.
> Does anyone have any insight?

Sunday, February 26, 2012

Error in datetime validation

xml including a datetime attribute is failing to validate against a simple schema held in an XML schema collection

The same xml validates correctly against the same schema in .Net

Is this a bug? (same behaviour is seen with dates)

Repro follows:

CREATE XML SCHEMA COLLECTION MyCollection AS '
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ns" xmlns:ns="http://ns" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
<xs:complexType name="TestType">
<xs:attribute name="id" type="xs:string" use="required"> </xs:attribute>
<xs:attribute name="startDate" type="xs:dateTime" ></xs:attribute>
</xs:complexType>
<xs:element name="TestList" type="ns:TestType">
</xs:element>
</xs:schema>';
go
declare @.xmlvar xml(MyCollection)
set @.xmlvar=
'<TestList xmlns="http://ns" id="D882BA19-81FA-4F99-845D-D8AE57BD0699" startDate="2006-01-02T00:00:00" ></TestList>'


Msg 6926, Level 16, State 1, Line 2
XML Validation: Invalid simple type value: '2006-01-02T00:00:00'. Location: /*:TestList[1]/@.*:startDate

I have just found that the SQL implementation of XML requires the time zone - e.g. 'Z' suffix - but that the .Net implementation does not need the zone.

I now no longer have a problem as I will use the Z suffix - but it would be useful to know whether system.xml or SQL2005 are currently exhibiting the intended behaviour (assuming a target of consistency between the two)

|||

Your observation is correct that the server's schema processor requires the timezone specification - it normalizes the value to UTC and does not preserve the timezone.

The server uses its own XML schema validator, which is different from those in System.Xml and MSXML. As such, any server-side error is generated bu the server's XML schema processor. To isolate whether the error is given by the client or the server, invoke the validation at the server.

Hope this helps.

Thank you,

Shankar

Program Manager

Microsoft SQL Server

|||

Thanks Shankar - As I said in my last post, this is not a problem for me now. However, this is the second time that I have encountered tighter validation in the SQL engine than in system.xml (Previous thread was "XML Schema extension behaving differently between SQL2005 and VB.Net 2.0 ")

This can cause problems when developers do early development and testing saving to XML files. It means that when database integration takes place a different set of problems can occur - which would be completely avoidable if the validation was consistent between system.xml and the SQL engine.

Is there a goal to achieve consistency soon?

If not then it would certainly be useful to have sight of the known differences - I understand from Denis Ruckebusch in the previous thread that a list is being compiled

Thanks

|||

We are looking at relaxing some of the implementation restrictions in the server side validation based on feedback like yours and by removing some of the obstacles that required us to introduce the restrictions in the first place.

Best regards

Michael

|||

Hi Michael

That's encouraging - but for current development it would be very useful to have visibility of the known list of differences

Thanks