weird xquery error



Hi...

I've been playing with the xml and schema types and querying on them and I
got some help with xquery from Wei and Han. As I built out more samples in
the collection I ran into a weird error with one xquery:

Msg 9314, Level 16, State 1, Line 3
XQuery [xml_test.xml_col.value()]: Cannot implicitly atomize or apply
'fn:data()'
to complex content elements, found type '{http://ex.org/T2}:age'
within inferred type
'(element({http://ex.org/LogansRun}:age,#anonymous) |
element({http://ex.org/T2}:age,#anonymous)) ?'.

running the query
select xml_col.value('(//*:age)[1]', 'varchar(100)') from xml_test;
(Han recommended this as a very concise form for a query, without all the
namespace declarations)

on the schema collection:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
<xsd:simpleType name="noContent">
<xsd:restriction base="xsd:string">
<xsd:length value="1" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified"
xmlns="http://ex.org/LogansRun"; targetNamespace="http://ex.org/LogansRun";>
<xsd:element name="age">
<xsd:simpleType>
<xsd:restriction base="xsd:float">
<xsd:minInclusive value="0" />
<xsd:maxInclusive value="30" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified"
xmlns="http://ex.org/T2"; targetNamespace="http://ex.org/T2";>
<xsd:element name="age">
<xsd:complexType>
<xsd:complexContent>
<xsd:sequence>
<xsd:element name="birthday" type="xsd:string" />
<xsd:element name="mother" type="xsd:string" minOccurs="0" />
<xsd:element name="father" type="xsd:string" minOccurs="0" />
<xsd:element name="sibling" type="xsd:string" minOccurs="0"
maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified"
xmlns="http://ex.org/T3"; targetNamespace="http://ex.org/T3"; >
<xsd:element name="person">
<xsd:complexType>
<xsd:complexContent>
<xsd:sequence>
<xsd:element name="age" type="xsd:string" />
<xsd:element name="mother" type="xsd:string" minOccurs="0" />
<xsd:element name="father" type="xsd:string" minOccurs="0" />
<xsd:element name="sibling" type="xsd:string" minOccurs="0"
maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Each of the schema in the collection has only one definition for an "age"
element. Yes, they're all different but to serialize them as a string it
doesn't seem like the difference is material.

Could someone explain why it's throwing an error? There isn't even any data
in the table, so it's barking at a semantic level, not a data conflict level.

Thanks
-Mark

.



Relevant Pages

  • Bug with value method, schema and parent axis?
    ... XQuery: 'value' requires a ... The statement is OK when the schema is removed from the the xml column. ... Is this a bug or did I miss something? ...
    (microsoft.public.sqlserver.xml)
  • Re: XML XPath problem
    ... The problem is that your schema allows /i:analysis/i:cube to produce more than one element. ... INSERT INTO bookmark VALUES (' ... WHERE BookmarkDoc.exist('declare namespace i="http://activeinterface.com/intrasight";; ... 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. ...
    (microsoft.public.sqlserver.xml)
  • Re: XML XPath problem
    ... Here is the schema (note that in my original posting that I had not used ... SELECT BookmarkID FROM bookmark ... How does one properly express such things in TSQL? ... The T-SQL's fine--the problem is with the XQuery. ...
    (microsoft.public.sqlserver.xml)