Solved

How to force an empty XML tag to be loaded into DB table as an empty string

Posted on 2009-07-13
3
341 Views
Last Modified: 2013-11-05
Hi all

I am not sure whether this is an SQL question or an XML question but I have a VB6 application that takes data in an XML file and loads it into a database table using an SQLXMLBulkLoad object.

It does it with issue except for the fact that tags that are empty i.e. have no value get inserted into tha DB table as NULLS and I want them to be empty strings.
 So for example if I have the following XML
<Address1>15 Peters Street</Address1>
<Address2>Hobble End</Address2>
<Address3>Wiltshire</Address3>
<Address4></Address4>
<Address5></Address5>

Address lines 1 to 3 get loaded as strings as expected but address lines 4 and 5 are NULL.
So what do I need my XML to look like for the transformation process to recognise the contents as '' and not NULL.

If it helps I do the bulk as follows:

Set objBulkLoad = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad.3.0")
objBulkLoad.ConnectionString = gstrMmConnection
objBulkLoad.ForceTableLock = True
   
objBulkLoad.Execute gstrSchemaPath, gstrDirPath & strFileName

I have a .xsd scheme file that maps the XML tags to the relevant database columns and that looks like this:

<ElementType name="AddressLine1" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine2" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine3" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine4" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine5" dt:type="string" sql:datatype="varchar(38)"/>

<ElementType name="Member" sql:relation="Adresses" >
      <element type="AddressLine1" sql:field="MemAdd1"/>
      <element type="AddressLine2" sql:field="MemAdd2"/>
      <element type="AddressLine3" sql:field="MemAdd3"/>
      <element type="AddressLine4" sql:field="MemAdd4"/>
      <element type="AddressLine5" sql:field="MemAdd5"/>
</ElementType>

Cheers
Sam
0
Comment
Question by:Samm1502
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
Comment Utility
You can, in SQL, change the columns to not allow null and put a default on '' (quote quote) on them.
0
 

Author Comment

by:Samm1502
Comment Utility
I will try that.  Thanks Sam
0
 

Author Closing Comment

by:Samm1502
Comment Utility
The only reason I didn't give this an A is that I couldn't in fact disallow NULLS and add a default to the column without getting a crash saying column x does not allow NULL values.  What I had to do was allow NULLS then also place a default('') on the column and it works great now.

Many thanks
Sam
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now