syw
syw

Reputation: 11

How to prevent minimized empty xml tags using XQuery from SQL Server 2005

I am generating XML from SQL Server 2005 using a SELECT statement with XQuery syntax.

Is there a way to generate end tags for empty elements? Basically the xml output generated from this sql statement feeds into a "legacy" c# xml parser that doesn't like minimized tag elements! Otherwise everything works fine.

select  
    -- (this generates empty xml element which throws out the parser)
    main.sub.query('schoolname').value('.','varchar(50)') "newparent/newchild/newschoolname"  
from
    @xml.nodes('/parent/child') AS main(sub)
for xml path(''), type)

Thanks

Upvotes: 1

Views: 569

Answers (1)

Paul Sweatte
Paul Sweatte

Reputation: 24627

Use an XSLT processor to transform the empty tags to paired tags, or remove them as in the following questions:

Upvotes: 1

Related Questions