Tuesday, January 1, 2008

asp.net expanding empty xml nodes

Sometimes I use an xmldom to write HTML (instead of an htmltextwriter) - this is so that I can use appendChild etc from the server side.
One small problem with doing this, when you read the innerXML property, by default an xmldom will collapse empty nodes to short tag syntax: instead of
If you run the following block of code against your dom, the tags will render as full tags, and create valid html markup.


for each element as XmlElement in HtmlContent.SelectNodes("//*[not(node())]")
element.isEmpty = false
next

No comments: