dbTalk Databases Forums  

Can FOR XML PATH create truly _empty_ elements?

microsoft.public.sqlserver.xml microsoft.public.sqlserver.xml


Discuss Can FOR XML PATH create truly _empty_ elements? in the microsoft.public.sqlserver.xml forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Lee Marks
 
Posts: n/a

Default Re: Can FOR XML PATH create truly _empty_ elements? - 12-05-2008 , 07:01 AM






Thanks for the reply Martin.

I was aware of xsi:nil, but it's a workaround and I want to be sure there
isn't a proper way to do it before I do something like that. It is surprising
to me that FOR XML PATH is capable of generating all manner of complex xml
but not it seems a simple empty tag!

I have also discovered another workaround, which is to set the mixed
attribute to true on the tags associated type. ie:

create XML SCHEMA COLLECTION MySchema As
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="tag">
<xs:complexType mixed="true">
<xs:sequence/>
</xs:complexType>
</xs:element>
</xs:schema>
'

now if I do

declare @xml xml(MySchema)
set @xml = (select '' as 'tag' for xml path (''), type)

it returns me a genuinely empty tag.

Still not perfect because these tags are now not statically enforced to have
no text value but at least they can't have attributes or sub-elements so it's
getting close.



Reply With Quote
  #22  
Old   
Lee Marks
 
Posts: n/a

Default Re: Can FOR XML PATH create truly _empty_ elements? - 12-05-2008 , 07:01 AM






Thanks for the reply Martin.

I was aware of xsi:nil, but it's a workaround and I want to be sure there
isn't a proper way to do it before I do something like that. It is surprising
to me that FOR XML PATH is capable of generating all manner of complex xml
but not it seems a simple empty tag!

I have also discovered another workaround, which is to set the mixed
attribute to true on the tags associated type. ie:

create XML SCHEMA COLLECTION MySchema As
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="tag">
<xs:complexType mixed="true">
<xs:sequence/>
</xs:complexType>
</xs:element>
</xs:schema>
'

now if I do

declare @xml xml(MySchema)
set @xml = (select '' as 'tag' for xml path (''), type)

it returns me a genuinely empty tag.

Still not perfect because these tags are now not statically enforced to have
no text value but at least they can't have attributes or sub-elements so it's
getting close.



Reply With Quote
  #23  
Old   
Lee Marks
 
Posts: n/a

Default Re: Can FOR XML PATH create truly _empty_ elements? - 12-05-2008 , 07:01 AM



Thanks for the reply Martin.

I was aware of xsi:nil, but it's a workaround and I want to be sure there
isn't a proper way to do it before I do something like that. It is surprising
to me that FOR XML PATH is capable of generating all manner of complex xml
but not it seems a simple empty tag!

I have also discovered another workaround, which is to set the mixed
attribute to true on the tags associated type. ie:

create XML SCHEMA COLLECTION MySchema As
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="tag">
<xs:complexType mixed="true">
<xs:sequence/>
</xs:complexType>
</xs:element>
</xs:schema>
'

now if I do

declare @xml xml(MySchema)
set @xml = (select '' as 'tag' for xml path (''), type)

it returns me a genuinely empty tag.

Still not perfect because these tags are now not statically enforced to have
no text value but at least they can't have attributes or sub-elements so it's
getting close.



Reply With Quote
  #24  
Old   
Lee Marks
 
Posts: n/a

Default Re: Can FOR XML PATH create truly _empty_ elements? - 12-05-2008 , 07:01 AM



Thanks for the reply Martin.

I was aware of xsi:nil, but it's a workaround and I want to be sure there
isn't a proper way to do it before I do something like that. It is surprising
to me that FOR XML PATH is capable of generating all manner of complex xml
but not it seems a simple empty tag!

I have also discovered another workaround, which is to set the mixed
attribute to true on the tags associated type. ie:

create XML SCHEMA COLLECTION MySchema As
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="tag">
<xs:complexType mixed="true">
<xs:sequence/>
</xs:complexType>
</xs:element>
</xs:schema>
'

now if I do

declare @xml xml(MySchema)
set @xml = (select '' as 'tag' for xml path (''), type)

it returns me a genuinely empty tag.

Still not perfect because these tags are now not statically enforced to have
no text value but at least they can't have attributes or sub-elements so it's
getting close.



Reply With Quote
  #25  
Old   
Lee Marks
 
Posts: n/a

Default Re: Can FOR XML PATH create truly _empty_ elements? - 12-05-2008 , 07:01 AM



Thanks for the reply Martin.

I was aware of xsi:nil, but it's a workaround and I want to be sure there
isn't a proper way to do it before I do something like that. It is surprising
to me that FOR XML PATH is capable of generating all manner of complex xml
but not it seems a simple empty tag!

I have also discovered another workaround, which is to set the mixed
attribute to true on the tags associated type. ie:

create XML SCHEMA COLLECTION MySchema As
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="tag">
<xs:complexType mixed="true">
<xs:sequence/>
</xs:complexType>
</xs:element>
</xs:schema>
'

now if I do

declare @xml xml(MySchema)
set @xml = (select '' as 'tag' for xml path (''), type)

it returns me a genuinely empty tag.

Still not perfect because these tags are now not statically enforced to have
no text value but at least they can't have attributes or sub-elements so it's
getting close.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.