Home All Groups Group Topic Archive Search About

Getting Empty Tags Returned From The Server

Author
16 Nov 2005 6:52 PM
Gary

I have been using the SQLXML 3.0 Schema stuff to return XML over XPath.
Everything is working fine except some times I don't seem to get the
empty tags returned if there are NULL values in the database and at
other times I do. So I'd like something like

<ROOT>
<foo>Hi</foo>
<bar/>
</ROOT>

but in some schemas I have (it isn't inconsistent across requests on
the same schema):

<ROOT>
<foo>Hi</foo>
</ROOT>

I've set minOccurs to 1 in all cases and the schema is designed around
a sequence. What I'd like to know is if there are any rules that govern
the production of an empty tag, rather than omitting it entirely, that
I can work with.

Thanks,

Gary

Author
17 Nov 2005 7:29 AM
Michael Rys [MSFT]
Normally NULL values should be mapped to absent elements. So if you see an
element, it normally is not really NULL in the database, or you had some
underlying join that generated an entity element.

Can you give a small repro?

Thanks
Michael

Show quoteHide quote
"Gary" <gary.ian.stew***@gmail.com> wrote in message
news:1132167157.076723.260120@g14g2000cwa.googlegroups.com...
>I have been using the SQLXML 3.0 Schema stuff to return XML over XPath.
> Everything is working fine except some times I don't seem to get the
> empty tags returned if there are NULL values in the database and at
> other times I do. So I'd like something like
>
> <ROOT>
> <foo>Hi</foo>
> <bar/>
> </ROOT>
>
> but in some schemas I have (it isn't inconsistent across requests on
> the same schema):
>
> <ROOT>
> <foo>Hi</foo>
> </ROOT>
>
> I've set minOccurs to 1 in all cases and the schema is designed around
> a sequence. What I'd like to know is if there are any rules that govern
> the production of an empty tag, rather than omitting it entirely, that
> I can work with.
>
> Thanks,
>
> Gary
>
Are all your drivers up to date? click for free checkup

Author
17 Nov 2005 9:51 AM
Gary
I'd be happy to:

The base XSD file has something like (I'm hoping truncating it wouldn't
change the way the fields act):

<xsd:annotation>
<xsd:documentation>Example Schema.</xsd:documentation>
<xsd:appinfo>
  <sql:relationship name="LinkAddress" parent="Person"
parent-key="AddressGUID" child="Address" child-key="guid" />
  <sql:relationship name="EventList" parent="Person" parent-key="guid"
child="Event" child-key="PersonRef" />
  </xsd:appinfo>
</xsd:annotation>

<xsd:complexType mixed="false" name="LSA_PERSON">
<xsd:sequence>
  <xsd:element name="DeathFlag" default="0" type="xsd:boolean"
minOccurs="1" />
   [...]
  <xsd:element name="AddressGUID" type="xsd:string" minOccurs="1" />
  <xsd:element ref="Address" sql:relationship="LinkAddress"
maxOccurs="1" minOccurs="1" />
   <xsd:element name="Title" type="lsa:LSA_TITLE_TYPE" minOccurs="1" />
   <xsd:element name="FirstName" type="lsa:LSA_NAME_COMPONENT"
minOccurs="1"/>
   <xsd:element name="LastName" type="lsa:LSA_NAME_COMPONENT"
minOccurs="1"/>
   <xsd:element ref="lsa:Event" sql:relationship="EventList"
maxOccurs="unbounded" minOccurs="0" />

Values such as title are recorded as NULL on the database but appear as
empty tags on an XPath return. The fields in address tag that are NULL
do not appear at all. If the Title, FirstName and LastName appear
before the Address table join then they don't seem to appear at all.

Is the best solution to not allow NULLs and give a dummy default value
then?

I'd happily give you more information if you need any.

Thanks,

Gary
Author
17 Nov 2005 7:35 PM
Michael Rys [MSFT]
I forwarded this to our internal experts. But I think the main culprit may
be the following:

The Title element gets mapped to a simple column within the same table. I
think the mapping semantics uses the minOccurs="1" to imply that such NULL
values need to be mapped to a present element. Does the element still appear
if you use minOccurs="0"?

The Address element on the other hand get generated through a join. In the
case of the join, the mapping algorithm does not create a present element if
no join partners have been found.

I will check if my interpretation is correct and let you all know if not.

Best regards
Michael

Show quoteHide quote
"Gary" <gary.ian.stew***@gmail.com> wrote in message
news:1132221062.977516.190800@o13g2000cwo.googlegroups.com...
> I'd be happy to:
>
> The base XSD file has something like (I'm hoping truncating it wouldn't
> change the way the fields act):
>
> <xsd:annotation>
> <xsd:documentation>Example Schema.</xsd:documentation>
> <xsd:appinfo>
>  <sql:relationship name="LinkAddress" parent="Person"
> parent-key="AddressGUID" child="Address" child-key="guid" />
>  <sql:relationship name="EventList" parent="Person" parent-key="guid"
> child="Event" child-key="PersonRef" />
>  </xsd:appinfo>
> </xsd:annotation>
>
> <xsd:complexType mixed="false" name="LSA_PERSON">
> <xsd:sequence>
>  <xsd:element name="DeathFlag" default="0" type="xsd:boolean"
> minOccurs="1" />
>   [...]
>  <xsd:element name="AddressGUID" type="xsd:string" minOccurs="1" />
>  <xsd:element ref="Address" sql:relationship="LinkAddress"
> maxOccurs="1" minOccurs="1" />
>   <xsd:element name="Title" type="lsa:LSA_TITLE_TYPE" minOccurs="1" />
>   <xsd:element name="FirstName" type="lsa:LSA_NAME_COMPONENT"
> minOccurs="1"/>
>   <xsd:element name="LastName" type="lsa:LSA_NAME_COMPONENT"
> minOccurs="1"/>
>   <xsd:element ref="lsa:Event" sql:relationship="EventList"
> maxOccurs="unbounded" minOccurs="0" />
>
> Values such as title are recorded as NULL on the database but appear as
> empty tags on an XPath return. The fields in address tag that are NULL
> do not appear at all. If the Title, FirstName and LastName appear
> before the Address table join then they don't seem to appear at all.
>
> Is the best solution to not allow NULLs and give a dummy default value
> then?
>
> I'd happily give you more information if you need any.
>
> Thanks,
>
> Gary
>
Author
18 Nov 2005 4:28 PM
Gary
I tested with a minOccurs of 0 on a NULL field and the empty element
still appeared.

Is there a good way to get an empty element from the server? The field
doesn't need to be NULL; I can populate it with a value.

Thanks for all your help,

Gary
Author
18 Nov 2005 8:27 PM
Michael Rys [MSFT]
The way to map NULL to an element is to set the element in the schema to be
nillable. In that case, NULL values are mapped to an element with no content
and an attribute xsi:nil="true".

Note that I am concerned about your element still getting generated with a
NULL field by default. That should not happen since NULLs per default are
mapped to absence. Are you sure it is NULL and not a zero-length string?

Also, if you want your elements to be empty (and have no special
attributes), you want the value to be the zero-length string.

Best regards
Michael

Show quoteHide quote
"Gary" <gary.ian.stew***@gmail.com> wrote in message
news:1132331336.169241.92640@g47g2000cwa.googlegroups.com...
>I tested with a minOccurs of 0 on a NULL field and the empty element
> still appeared.
>
> Is there a good way to get an empty element from the server? The field
> doesn't need to be NULL; I can populate it with a value.
>
> Thanks for all your help,
>
> Gary
>
Author
21 Nov 2005 11:02 AM
Gary
Looks like it is a NULL I can directly mail you the Schema and the
table creation script, if you like, and you can see if you can recreate
it. Is there anything else you'd like?

Thanks for all your help,

Gary
Author
14 Dec 2005 11:37 PM
Michael Rys [MSFT]
Hi Gary

Sorry for the late reply (I was busy with some business travel). If you
still have the issue, please directly send me the schema, table creation and
one or two rows that can repro the issue. I will forward it to the team and
see if we can find the issue...

Thanks
Michael


Show quoteHide quote
"Gary" <gary.ian.stew***@gmail.com> wrote in message
news:1132570196.274669.84580@g44g2000cwa.googlegroups.com...
> Looks like it is a NULL I can directly mail you the Schema and the
> table creation script, if you like, and you can see if you can recreate
> it. Is there anything else you'd like?
>
> Thanks for all your help,
>
> Gary
>
Author
21 Nov 2005 2:46 PM
Gary
Sorry in addition to my last reply is there a way of representing the
empty string as an insert in an XML document that you are putting up
using an updategram?

Thanks,

Gary

Bookmark and Share