![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#3
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#4
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#5
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#6
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#7
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#8
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#9
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
#10
| |||
| |||
|
|
I'm having difficulty doing something that should be really simple. I need to be able to generate empty elements (eg. <tag/>) using FOR XML PATH. I would have thought that this should work: declare @xml xml set @xml = (select '' as 'tag' for xml path (''), type) This creates "<tag></tag>" rather than "<tag/>". There should be no difference but in fact the first one has an empty text node in it, as demonstrated by this query: select @xml.query('if (/tag/text()) then <yes/> else <no/>') which returns <yes/>. This problem doesn't occur if I type the xml literally, ie set @xml = '<tag></tag>' or set @xml = '<tag/>' both produce genuinely empty elements that will produce <no/> when run against the xquery above. |
![]() |
| Thread Tools | |
| Display Modes | |
| |