By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

Improperly nested XML when column contains NULL

P: n/a
I'm getting improperly nested xml when a column contains null.
I modified the first row (customer ALFKI) to have a NULL Address
column.

I'm using the following XSD Annotated Schema against the NorthWind
database:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xs:element name="customer" sql:relation="Customers"
sql:key-fields="CustomerID">
<xs:complexType>
<xs:sequence>
<xs:element name="name" sql:field="ContactName"
type="xs:string" />
<xs:element name="address" sql:is-constant="true">
<xs:complexType>
<xs:sequence>
<xs:element name="street" sql:field="Address"
type="xs:string" />
<xs:element name="city" sql:field="City"
type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" sql:field="CustomerID" type="xs:string"
/>
</xs:complexType>
</xs:element>
</xs:schema>

When run with the following query template:

<resources xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:xpath-query>customer[@id='ALFKI' or
@id='ANATR']</sql:xpath-query>
</resources>

I get the following XML:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<customer id="ALFKI">
<name>Maria Anders</name>
<address>
<street>
<city>Berlin</city>
</street>
</address>
<customer id="ANATR">
<name>Ana Trujillo</name>
<address>
<street>Avda. de la Constitución 2222</street>
<city>México D.F.</city>
</address>
</customer>
</customer>
</resources>

Notice how the first customer has the <city> tag nested inside the
<street> tag, but the second customer has the <city> tag as a sibling
to <street>

Can anyone explain why this is happening and what the solution might
be (short of modifying my database to not accept null values in
certain columns)?

Thanks,

Jerry Collings
MyFamily.com, Inc.
jc*******@myfamilyinc.com
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I found a problem in some post processing code I was using that
handled empty elements improperly.
I could see that the annotated schema was working after I removed this
post processing step.

Jerry

jc*******@myfamilyinc.com (Jerry Collings) wrote in message news:<2d**************************@posting.google. com>...
I'm getting improperly nested xml when a column contains null.
I modified the first row (customer ALFKI) to have a NULL Address
column.

I'm using the following XSD Annotated Schema against the NorthWind
database:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xs:element name="customer" sql:relation="Customers"
sql:key-fields="CustomerID">
<xs:complexType>
<xs:sequence>
<xs:element name="name" sql:field="ContactName"
type="xs:string" />
<xs:element name="address" sql:is-constant="true">
<xs:complexType>
<xs:sequence>
<xs:element name="street" sql:field="Address"
type="xs:string" />
<xs:element name="city" sql:field="City"
type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" sql:field="CustomerID" type="xs:string"
/>
</xs:complexType>
</xs:element>
</xs:schema>

When run with the following query template:

<resources xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:xpath-query>customer[@id='ALFKI' or
@id='ANATR']</sql:xpath-query>
</resources>

I get the following XML:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<customer id="ALFKI">
<name>Maria Anders</name>
<address>
<street>
<city>Berlin</city>
</street>
</address>
<customer id="ANATR">
<name>Ana Trujillo</name>
<address>
<street>Avda. de la Constitución 2222</street>
<city>México D.F.</city>
</address>
</customer>
</customer>
</resources>

Notice how the first customer has the <city> tag nested inside the
<street> tag, but the second customer has the <city> tag as a sibling
to <street>

Can anyone explain why this is happening and what the solution might
be (short of modifying my database to not accept null values in
certain columns)?

Thanks,

Jerry Collings
MyFamily.com, Inc.
jc*******@myfamilyinc.com

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.