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

565 views Asked by At

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

1

There are 1 answers

1
Paul Sweatte On

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