nsIDOMWindow dw = webBrowser.getContentDOMWindow();
nsISelection selection = dw.getSelection();
StringBuilder builder = new StringBuilder();
for(int i = 0; i< selection.getRangeCount(); i++) {
nsIDOMRange idomRange = selection.getRangeAt(i);
nsIDOMDocumentFragment fragment = idomRange.cloneContents();
nsIDOMNodeList nodeList = fragment.getChildNodes();
for(int k = 0; k < nodeList.getLength(); k++) {
buildHTMLNode(0, builder, nodeList.item(k));
}