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

prototype.js sortables text selection

Just a quick note; if you encounter an issue with text selecting when you're trying to drag objects in IE; I use the following code to 'fix' it.
Be warned, it disables the text selection for the whole browser window, so you have to conditionally renable it when you want it.

Event.observe(window,'load',function(e){
if(Prototype.Browser.IE)
{
$$('input, select, textarea')
.invoke('observe','blur',function(e){
disableIETextSelection();
})
.invoke('observe','click',function(e){
enableIETextSelection();
})
.invoke('observe','focus',function(e){
enableIETextSelection();
});

disableIETextSelection();
}
});

function disableIETextSelection()
{
document.body.ondrag = function () { return false; };
document.body.onselectstart = function () { return false; };
}
function enableIETextSelection()
{
document.body.ondrag = null;
document.body.onselectstart = null;
}