Re: SQL 2005 OPENXML doesnt understand xsi:nil
- From: "Michael Rys [MSFT]" <mrys@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 11 Jul 2006 14:22:41 -0700
Dan is right. OpenXML operates on an untyped XML DOM tree. Thus xsi:nil is
just another attribute...
The nodes() method in SQL Server 2005 will understand xsi:nil if you have
the XML datatype instance schema validated.
Best regards
Michael
"Dan Sullivan" <danATpluralsight.com> wrote in message
news:964a9ae61ff598c8731b3f418748@xxxxxxxxxxxxxxxxxxxxx
I don't think OPENXML has a builtin understanding of xsi:nil like datagrams
do. But you can get it to produce the results you want with an appropriate
predicate on the OrganizationCode pattern. You have to add the xsi
namespace to the sp_xml_preparedocument for this to work Here is an example
that reads the OrganizationCode as NULL.
If you are going to be running on SQL Server 2005 though, you might find
it easier to shred using the nodes() function.
--DROP TABLE #Organization
DECLARE @doc VARCHAR(4000)
SET @doc = '<Organization
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OrganizationID>1</OrganizationID>
<Name>My Travel</Name>
<OrganizationTypeID>1</OrganizationTypeID>
<OrganizationCode xsi:nil="true" />
</Organization>'
DECLARE @iprofile INT
exec sp_xml_preparedocument @iprofile output, @doc, '<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
SELECT * INTO #Organization
FROM OPENXML (@iProfile, '/Organization',2)
WITH (
[OrganizationID] [bigint] './OrganizationID',
[Name] [nvarchar](100) './Name',
[OrganizationCode] [varchar](30)
'./OrganizationCode[xsi:nil!="true"]',
[OrganizationTypeID] [smallint] './OrganizationTypeID'
)
SELECT * FROM #Organization
Dan
I have an xml document that has elements that are nil (xsi:nil="true")
but OPENXML created a column that is empty "", not NULL. Any ideas
why?
<Organization>
<OrganizationID>1</OrganizationID>
<Name>My Travel</Name>
<OrganizationCode xsi:nil="true" />
<OrganizationTypeID>1</OrganizationTypeID>
</Organization>
SELECT * INTO #Organization
FROM OPENXML (@iProfile, '/Organization',2)
WITH (
[OrganizationID] [bigint] './OrganizationID',
[Name] [nvarchar](100) './Name',
[OrganizationCode] [varchar](30) './OrganizationCode',
[OrganizationTypeID] [smallint] './OrganizationTypeID'
)
OrganizationID Name
OrganizationCode
OrganizationTypeID
--------------------
----------------------------------------------------------------------
------------------------------
------------------------------ ------------------
1 My Travel
1
OrganizationCode should be NULL
.
- References:
- SQL 2005 OPENXML doesnt understand xsi:nil
- From: tempdba
- Re: SQL 2005 OPENXML doesnt understand xsi:nil
- From: Dan Sullivan
- SQL 2005 OPENXML doesnt understand xsi:nil
- Prev by Date: Re: How should I create XML Schema for this xml? thanks
- Next by Date: Re: XMLColumn.query
- Previous by thread: Re: SQL 2005 OPENXML doesnt understand xsi:nil
- Next by thread: How should I create XML Schema for this xml? thanks
- Index(es):
Relevant Pages
|
Loading