Re: XML XPath problem
- From: Dan Sullivan danATpluralsight.com
- Date: Mon, 26 Jun 2006 22:54:43 +0000 (UTC)
The problem is that your schema allows /i:analysis/i:cube to produce more than one element. To resolve your predicate XQuery in effect does
string(/i:analysis/i:cube)
and is unhappy becase it looks at the schema and finds that more than one cube is possible. I think what you want to see if any cube contains "Customers". Here is a slight change to your query that does that.
XS2 is the XML SCHEMA COLLECTION that contains your schema.
CREATE TABLE bookmark
(
BookmarkID int identity primary key,
BookmarkDoc xml(XS2)
)
INSERT INTO bookmark VALUES ('
<i:analysis xmlns:i="http://activeinterface.com/intrasight">
<i:catalog>asdf</i:catalog>
<i:cube>asdfadsf</i:cube>
<i:properties>
<i:Title rows="1"/>
<i:Description rows="1"/>
<i:Notes rows="9"/>
</i:properties>
<i:cube>Customers</i:cube>
</i:analysis>'
)
SELECT BookmarkID, BookmarkDoc FROM bookmark
WHERE BookmarkDoc.exist('declare namespace i="http://activeinterface.com/intrasight";
/i:analysis[i:cube[string()=''Customers'']]') = 1
GO
BTW XQuery in SQL Server does static analysis, i.e. it looks at the schema if there is one, before it even tries to execute the query. if you were not using a schema it wouldn't be a problem.
Dan
Brandon,
Thanks for replying - this really has me stumped.
I figured it was getting stuck on those escaped single quotes around
'Customers' or square brackets. But if the TSQL looks ok, then perhaps
it is
a schema issue.
Here is the schema (note that in my original posting that I had not
used
actual namespace)
<?xml version="1.0" encoding="iso-8859-1"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://activeinterface.com/intrasight"
targetNamespace="http://activeinterface.com/intrasight"
elementFormDefault="qualified" >
<xsd:annotation>
<xsd:documentation>
This is the simplified schema for Intrasight GUI XML serialization
</xsd:documentation>
</xsd:annotation>
<xsd:complexType name="PropType">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="rows" type="xsd:int" use="required" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:element name="analysis">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="catalog" type="xsd:string" />
<xsd:element name="cube" type="xsd:string" />
<xsd:element name="properties">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="PropType" />
<xsd:element name="Description" type="PropType" />
<xsd:element name="Notes" type="PropType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:any processContents="skip" namespace="##targetNamespace"
minOccurs="1" maxOccurs="unbounded"></xsd:any>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
"Brandon Berg [MSFT]" <branber@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:44a04cfc$1@xxxxxxxxxxxxxxxxxxxxx
"ChrisHarrington" <charrington-at-activeinterface.com> wrote in
message news:OesF7PVmGHA.4212@xxxxxxxxxxxxxxxxxxxxxxx
This TSQLThe T-SQL's fine--the problem is with the XQuery. What is the schema
SELECT BookmarkID FROM bookmark
WHERE BookmarkDoc.exist('declare namespace i="http://mynamespace";
/i:analysis[i:cube=''Customers'']') = 1
GO
return error:
Msg 9311, Level 16, State 1, Line 4
XQuery [bookmark.BookmarkDoc.exist()]: Heterogeneous sequences are
not
allowed in '=', found 'xdt:untypedAtomic' and 'xs:string'.
How does one properly express such things in TSQL?
for i:analysis?
--
Brandon Berg
Software Design Engineer
Microsoft SQL Server
.
- Follow-Ups:
- Re: XML XPath problem
- From: ChrisHarrington
- Re: XML XPath problem
- References:
- Re: XML XPath problem
- From: ChrisHarrington
- Re: XML XPath problem
- Prev by Date: Re: XML XPath problem
- Next by Date: Re: use XML to store custom metadata
- Previous by thread: Re: XML XPath problem
- Next by thread: Re: XML XPath problem
- Index(es):
Relevant Pages
|