Monday, March 26, 2012

Getting Strange Results using SQLXML and Schema

Hi there,
I've been using the nillable="true" technique to get NULLs returned as
empty elements from the database. In most cases it seems to work just
fine (though I've had the "Parent tag ID 'n' is not among the open
tags" a few times I've been able to resolve it) however in the case of
a table that mostly allows NULLs for all rows (or at least the ones I'm
interested in in the schema) that looks like:
<xsd:complexType name="ADDRESS_TYPE" >
<xsd:sequence>
<xsd:element name="AddressLine1" sql:field="AddressLine"
type="xsd:string" minOccurs="1" nillable="true" />
<xsd:element name="AddressLine2" sql:field="AddressLine2"
type="xsd:string" minOccurs="1" nillable="true" />
<xsd:element name="TownCity" default="" sql:field="TownCity"
type="xsd:string" minOccurs="1" nillable="true" />
(...)
</xsd:sequence>
<xsd:attribute name="id" sql:field="guid" />
</xsd:complexType>
I get results that look something like
<y0:Address id="598E61F5-43B6-45E6-983C-031AF6DB7607"/>
<y0:Address id="718E1BBD-5F41-44C4-B795-0B7F3F32B759"/>
<y0:Address id="8D003B08-39B8-4F3E-BCAF-0D069C936942"/>
<y0:AddressLine1>Test Lane</y0:AddressLine1>
<y0:AddressLine1 xsi:nil="true"/>
<y0:AddressLine1>Potter's Way</y0:AddressLine1>
<y0:AddressLine2/>
<y0:AddressLine2 xsi:nil="true"/>
<y0:AddressLine2>Pumpherston</y0:AddressLine2>
...
I saw the article on SQLXML (http://sqlxml.org/faqs.aspx?faq=28)
relating to this but as I'm not creating the XML Explicit queries
myself rather I'm using Schema I was wondering if anyone had any ideas
how to try and address this and pitfalls to avoid?
Thanks,
GaryThis usually means you havent fully specified the key fields for your tables
.
You should specify the key-fields annotation for every table in the mapping
schema. If you dont, your results can be non-deterministic and have issues
similar to the ones you are seeing.
http://msdn.microsoft.com/library/d...ations_9rsj.asp
If that doesnt work, post the mapping schema.
"Gary" wrote:

> Hi there,
> I've been using the nillable="true" technique to get NULLs returned as
> empty elements from the database. In most cases it seems to work just
> fine (though I've had the "Parent tag ID 'n' is not among the open
> tags" a few times I've been able to resolve it) however in the case of
> a table that mostly allows NULLs for all rows (or at least the ones I'm
> interested in in the schema) that looks like:
> <xsd:complexType name="ADDRESS_TYPE" >
> <xsd:sequence>
> <xsd:element name="AddressLine1" sql:field="AddressLine"
> type="xsd:string" minOccurs="1" nillable="true" />
> <xsd:element name="AddressLine2" sql:field="AddressLine2"
> type="xsd:string" minOccurs="1" nillable="true" />
> <xsd:element name="TownCity" default="" sql:field="TownCity"
> type="xsd:string" minOccurs="1" nillable="true" />
> (...)
> </xsd:sequence>
> <xsd:attribute name="id" sql:field="guid" />
> </xsd:complexType>
> I get results that look something like
> <y0:Address id="598E61F5-43B6-45E6-983C-031AF6DB7607"/>
> <y0:Address id="718E1BBD-5F41-44C4-B795-0B7F3F32B759"/>
> <y0:Address id="8D003B08-39B8-4F3E-BCAF-0D069C936942"/>
> <y0:AddressLine1>Test Lane</y0:AddressLine1>
> <y0:AddressLine1 xsi:nil="true"/>
> <y0:AddressLine1>Potter's Way</y0:AddressLine1>
> <y0:AddressLine2/>
> <y0:AddressLine2 xsi:nil="true"/>
> <y0:AddressLine2>Pumpherston</y0:AddressLine2>
> ....
> I saw the article on SQLXML (http://sqlxml.org/faqs.aspx?faq=28)
> relating to this but as I'm not creating the XML Explicit queries
> myself rather I'm using Schema I was wondering if anyone had any ideas
> how to try and address this and pitfalls to avoid?
> Thanks,
> Gary
>sql

No comments:

Post a Comment