RootElement has no real value, hence removed the class

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java
index b483199..7ec3e47 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java
@@ -19,7 +19,6 @@
 import org.eclipse.vex.core.internal.core.DisplayDevice;
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Element;
-import org.eclipse.vex.core.internal.dom.RootElement;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -168,7 +167,7 @@
 
 	@Test
 	public void testDefaultInheritance() throws Exception {
-		final RootElement simple = new RootElement("simple");
+		final Element simple = new Element("simple");
 		final Element defaults = new Element("defaults");
 		final Document doc = new Document(simple);
 		doc.insertElement(1, defaults);
@@ -431,7 +430,7 @@
 
 	@Test
 	public void testForcedInheritance() throws Exception {
-		final RootElement simple = new RootElement("simple");
+		final Element simple = new Element("simple");
 		final Element inherit = new Element("inherit");
 		final Document doc = new Document(simple);
 		doc.insertElement(1, inherit);
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/RuleTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/RuleTest.java
index 40ff84e..a824cb8 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/RuleTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/RuleTest.java
@@ -18,7 +18,6 @@
 import org.eclipse.core.runtime.QualifiedName;
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Element;
-import org.eclipse.vex.core.internal.dom.RootElement;
 
 /**
  * Test rule matching.
@@ -31,7 +30,7 @@
 		final StyleSheet ss = reader.read(url);
 		final List<Rule> rules = ss.getRules();
 
-		final RootElement a = new RootElement("a");
+		final Element a = new Element("a");
 		final Element b = new Element("b");
 		final Element c = new Element("c");
 		final Element d = new Element("d");
@@ -273,7 +272,7 @@
 		final StyleSheet ss = reader.read(url);
 		final List<Rule> rules = ss.getRules();
 
-		final RootElement a = new RootElement("a");
+		final Element a = new Element("a");
 		final Element ns = new Element(new QualifiedName("http://namespace/uri", "b"));
 
 		ns.setAttribute("color", "blue");
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java
index d86f22c..cb3e3f7 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java
@@ -39,7 +39,7 @@
 	}
 
 	public void testAttributeDefinition() throws Exception {
-		final Document doc = new Document(new RootElement("section"));
+		final Document doc = new Document(new Element("section"));
 		doc.setValidator(validator);
 		final Element sectionElement = doc.getRootElement();
 		final AttributeDefinition.Type adType = validator.getAttributeDefinitions(sectionElement).get(0).getType();
@@ -49,7 +49,7 @@
 	}
 
 	public void testEnumAttribute() throws Exception {
-		final Document doc = new Document(new RootElement("section"));
+		final Document doc = new Document(new Element("section"));
 		doc.setValidator(validator);
 		final Element sectionElement = doc.getRootElement();
 		final AttributeDefinition attributeDefinition = validator.getAttributeDefinitions(sectionElement).get(0);
@@ -89,7 +89,7 @@
 	public void testSectionElement() {
 		// <section> <title> a b </title> <para> </para> </section>
 		// 1 2 3 4 5 6 7
-		final Document doc = new Document(new RootElement("section"));
+		final Document doc = new Document(new Element("section"));
 		doc.setValidator(validator);
 		doc.insertElement(1, new Element("title"));
 		doc.insertText(2, "ab");
@@ -105,7 +105,7 @@
 	}
 
 	public void testOneKindOfChild() {
-		final Document doc = new Document(new RootElement("one-kind-of-child"));
+		final Document doc = new Document(new Element("one-kind-of-child"));
 		doc.setValidator(validator);
 		assertValidItemsAt(doc, 1, "section");
 	}
@@ -150,7 +150,7 @@
 	}
 
 	public void testValidateDocumentWithDTDAndNamespaces() throws Exception {
-		final Document doc = new Document(new RootElement(new QualifiedName("http://namespace/uri/is/not/registered", "section")));
+		final Document doc = new Document(new Element(new QualifiedName("http://namespace/uri/is/not/registered", "section")));
 		doc.setValidator(validator);
 		doc.insertElement(1, new Element("title"));
 		doc.insertText(2, "ab");
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DocumentContentModelTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DocumentContentModelTest.java
index eb3ee0c..e8bf5be 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DocumentContentModelTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DocumentContentModelTest.java
@@ -41,21 +41,21 @@
 

 	@Test

 	public void initializeWithPublicId() throws Exception {

-		model.initialize(null, "publicId", "systemId", new RootElement(new QualifiedName("schemaId", "rootElement")));

+		model.initialize(null, "publicId", "systemId", new Element(new QualifiedName("schemaId", "rootElement")));

 		assertEquals("publicId", model.getMainDocumentTypeIdentifier());

 		assertTrue(model.isDtdAssigned());

 	}

 

 	@Test

 	public void initializeWithSystemId() throws Exception {

-		model.initialize(null, null, "systemId", new RootElement(new QualifiedName("schemaId", "rootElement")));

+		model.initialize(null, null, "systemId", new Element(new QualifiedName("schemaId", "rootElement")));

 		assertEquals("systemId", model.getMainDocumentTypeIdentifier());

 		assertTrue(model.isDtdAssigned());

 	}

 

 	@Test

 	public void initializeWithNamespace() throws Exception {

-		model.initialize(null, null, null, new RootElement(new QualifiedName("schemaId", "rootElement")));

+		model.initialize(null, null, null, new Element(new QualifiedName("schemaId", "rootElement")));

 		assertEquals("schemaId", model.getMainDocumentTypeIdentifier());

 		assertFalse(model.isDtdAssigned());

 	}

@@ -94,7 +94,7 @@
 

 	@Test

 	public void useBaseUriForResolving() throws Exception {

-		model.initialize("file://base/uri/document.xml", null, null, new RootElement(new QualifiedName("schemaId", "rootElement")));

+		model.initialize("file://base/uri/document.xml", null, null, new Element(new QualifiedName("schemaId", "rootElement")));

 		final InputSource resolvedEntity = model.resolveEntity("UnknownPublicId", "UnknownSystemId.dtd");

 		assertNotNull(resolvedEntity);

 		assertEquals("file://base/uri/UnknownSystemId.dtd", resolvedEntity.getSystemId());

diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ParentTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ParentTest.java
index c3e1699..c172734 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ParentTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ParentTest.java
@@ -19,6 +19,11 @@
 	@Before

 	public void setUp() throws Exception {

 		parent = new TestParent();

+

+		final GapContent content = new GapContent(10);

+		content.insertElementMarker(0);

+		content.insertElementMarker(1);

+		parent.setContent(content, 0, 1);

 	}

 

 	@Test

@@ -129,6 +134,14 @@
 

 	private static class TestChild extends Node {

 		@Override

+		public void setParent(final Parent parent) {

+			super.setParent(parent);

+			if (parent != null) {

+				setContent(parent.getContent(), 0, 0);

+			}

+		}

+

+		@Override

 		public String getNodeType() {

 			return "Child";

 		}

diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/SchemaValidatorTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/SchemaValidatorTest.java
index b4628ca..44cb07c 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/SchemaValidatorTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/SchemaValidatorTest.java
@@ -137,7 +137,7 @@
 	@Test

 	public void validItemsFromSimpleSchema() throws Exception {

 		final Validator validator = new WTPVEXValidator();

-		final Document doc = new Document(new RootElement(P));

+		final Document doc = new Document(new Element(P));

 		doc.setValidator(validator);

 		doc.insertElement(1, new Element(B));

 		doc.insertElement(2, new Element(I));

@@ -162,7 +162,7 @@
 		 * needs their parent to find the definition of their content model.

 		 */

 		final Validator validator = new WTPVEXValidator();

-		final Document doc = new Document(new RootElement(CHAPTER));

+		final Document doc = new Document(new Element(CHAPTER));

 		doc.setValidator(validator);

 		doc.insertElement(1, new Element(TITLE));

 		doc.insertElement(3, new Element(P));

@@ -178,14 +178,14 @@
 

 	@Test

 	public void getAllRequiredNamespacesForSimpleSchema() throws Exception {

-		final Validator validator = new WTPVEXValidator(new DocumentContentModel(null, null, null, new RootElement(P)));

+		final Validator validator = new WTPVEXValidator(new DocumentContentModel(null, null, null, new Element(P)));

 		final Set<String> requiredNamespaces = validator.getRequiredNamespaces();

 		assertEquals(1, requiredNamespaces.size());

 	}

 

 	@Test

 	public void getAllRequiredNamespacesForComplexSchema() throws Exception {

-		final Validator validator = new WTPVEXValidator(new DocumentContentModel(null, null, null, new RootElement(CHAPTER)));

+		final Validator validator = new WTPVEXValidator(new DocumentContentModel(null, null, null, new Element(CHAPTER)));

 		final Set<String> requiredNamespaces = validator.getRequiredNamespaces();

 		assertEquals(2, requiredNamespaces.size());

 		assertTrue(requiredNamespaces.contains(CONTENT_NS));

diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java
index 43ed6b9..864bf3e 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TableLayoutTest.java
@@ -22,7 +22,6 @@
 import org.eclipse.vex.core.internal.css.StyleSheetReader;
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Element;
-import org.eclipse.vex.core.internal.dom.RootElement;
 
 public class TableLayoutTest extends TestCase {
 
@@ -74,7 +73,7 @@
 	}
 
 	private void resetDocument() {
-		document = new Document(new RootElement("root"));
+		document = new Document(new Element("root"));
 		context.setDocument(document);
 		caretPosition = 1;
 		rootBox = new RootBox(context, document.getRootElement(), 500);
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlockElementBox.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlockElementBox.java
index c040cbe..3f5b244 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlockElementBox.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlockElementBox.java
@@ -18,7 +18,6 @@
 import org.eclipse.vex.core.internal.css.StyleSheetReader;
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Element;
-import org.eclipse.vex.core.internal.dom.RootElement;
 
 public class TestBlockElementBox extends TestCase {
 
@@ -39,7 +38,7 @@
 	}
 
 	public void testBeforeAfter() throws Exception {
-		final RootElement root = new RootElement("root");
+		final Element root = new Element("root");
 		final Document doc = new Document(root);
 		doc.insertElement(1, new Element("beforeBlock"));
 		context.setDocument(doc);
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlocksInInlines.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlocksInInlines.java
index 3019721..156e06d 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlocksInInlines.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestBlocksInInlines.java
@@ -20,7 +20,6 @@
 import org.eclipse.vex.core.internal.css.StyleSheetReader;
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Element;
-import org.eclipse.vex.core.internal.dom.RootElement;
 
 /**
  * Tests proper function of a block-level element within an inline element. These must be layed out as a block child of
@@ -51,7 +50,7 @@
 	}
 
 	public void testBlockInInline() throws Exception {
-		final RootElement root = new RootElement("root");
+		final Element root = new Element("root");
 		final Document doc = new Document(root);
 		context.setDocument(doc);
 
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestDocumentTextBox.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestDocumentTextBox.java
index 7e8d8ca..fa886c5 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestDocumentTextBox.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestDocumentTextBox.java
@@ -18,7 +18,7 @@
 import org.eclipse.vex.core.internal.css.StyleSheetReader;
 import org.eclipse.vex.core.internal.css.Styles;
 import org.eclipse.vex.core.internal.dom.Document;
-import org.eclipse.vex.core.internal.dom.RootElement;
+import org.eclipse.vex.core.internal.dom.Element;
 
 /**
  * Tests the DocumentTestBox class. We focus here on proper offsets, since text splitting is tested thoroughly in
@@ -44,7 +44,7 @@
 	}
 
 	public void testSplit() throws Exception {
-		final RootElement root = new RootElement("root");
+		final Element root = new Element("root");
 		final Document doc = new Document(root);
 
 		final Styles styles = context.getStyleSheet().getStyles(root);
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestStaticTextBox.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestStaticTextBox.java
index a4b603d..84f1a5b 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestStaticTextBox.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/layout/TestStaticTextBox.java
@@ -19,13 +19,13 @@
 import org.eclipse.vex.core.internal.css.StyleSheet;
 import org.eclipse.vex.core.internal.css.StyleSheetReader;
 import org.eclipse.vex.core.internal.css.Styles;
-import org.eclipse.vex.core.internal.dom.RootElement;
+import org.eclipse.vex.core.internal.dom.Element;
 
 public class TestStaticTextBox extends TestCase {
 
 	FakeGraphics g;
 	LayoutContext context;
-	RootElement root = new RootElement("root");
+	Element root = new Element("root");
 	Styles styles;
 
 	@Override
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/VexWidgetTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/VexWidgetTest.java
index 861d8fb..2093c6b 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/VexWidgetTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/VexWidgetTest.java
@@ -25,7 +25,6 @@
 import org.eclipse.vex.core.internal.dom.DocumentFragment;
 import org.eclipse.vex.core.internal.dom.Element;
 import org.eclipse.vex.core.internal.dom.Node;
-import org.eclipse.vex.core.internal.dom.RootElement;
 import org.eclipse.vex.core.internal.dom.Text;
 import org.eclipse.vex.core.internal.dom.Validator;
 import org.eclipse.vex.core.internal.validator.WTPVEXValidator;
@@ -108,14 +107,14 @@
 
 	private static Document createDocumentWithDTD(final String dtdIdentifier, final String rootElementName) {
 		final Validator validator = new WTPVEXValidator(dtdIdentifier);
-		final Document document = new Document(new RootElement(rootElementName));
+		final Document document = new Document(new Element(rootElementName));
 		document.setValidator(validator);
 		return document;
 	}
 
 	private static Document createDocument(final String rootSchemaIdentifier, final String rootElementName) {
 		final Validator validator = new WTPVEXValidator();
-		final Document document = new Document(new RootElement(new QualifiedName(rootSchemaIdentifier, rootElementName)));
+		final Document document = new Document(new Element(new QualifiedName(rootSchemaIdentifier, rootElementName)));
 		document.setValidator(validator);
 		return document;
 	}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/Rule.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/Rule.java
index f4ddc8f..f56d265 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/Rule.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/Rule.java
@@ -20,8 +20,8 @@
 import java.util.StringTokenizer;
 
 import org.eclipse.vex.core.internal.dom.CommentElement;
+import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.Element;
-import org.eclipse.vex.core.internal.dom.RootElement;
 import org.w3c.css.sac.AttributeCondition;
 import org.w3c.css.sac.CombinatorCondition;
 import org.w3c.css.sac.Condition;
@@ -145,7 +145,7 @@
 			return true;
 
 		case Selector.SAC_ROOT_NODE_SELECTOR:
-			return element instanceof RootElement;
+			return element.getParent() instanceof Document;
 
 		case Selector.SAC_NEGATIVE_SELECTOR:
 			break; // not yet supported
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java
index f3ee679..f0ee228 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/StyleSheet.java
@@ -182,7 +182,7 @@
 
 		final Styles styles = new Styles();
 		Styles parentStyles = null;
-		if (element.getParent() != null) {
+		if (element != null && element.getParentElement() != null) {
 			parentStyles = getStyles(element.getParentElement());
 		}
 
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
index 5da629f..3451da5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
@@ -27,10 +27,10 @@
  * Represents an XML document.
  * 
  */
-public class Document {
+public class Document extends Parent {
 
 	private final Content content;
-	private final RootElement rootElement;
+	private final Element rootElement;
 	private final ListenerList<DocumentListener, DocumentEvent> listeners = new ListenerList<DocumentListener, DocumentEvent>(DocumentListener.class);
 	private boolean undoEnabled = true;
 
@@ -48,13 +48,13 @@
 	 *            root element of the document. The document property of this RootElement is set by this constructor.
 	 * 
 	 */
-	public Document(final RootElement rootElement) {
+	public Document(final Element rootElement) {
 		content = new GapContent(100);
 		content.insertElementMarker(0);
 		content.insertElementMarker(0);
 
 		this.rootElement = rootElement;
-		rootElement.setDocument(this);
+		addChild(rootElement);
 		rootElement.setContent(content, 0, 1);
 	}
 
@@ -68,9 +68,10 @@
 	 *            RootElement of the document.
 	 * 
 	 */
-	public Document(final Content content, final RootElement rootElement) {
+	public Document(final Content content, final Element rootElement) {
 		this.content = content;
 		this.rootElement = rootElement;
+		addChild(rootElement);
 	}
 
 	/*
@@ -121,18 +122,18 @@
 
 	public void delete(final int startOffset, final int endOffset) throws DocumentValidationException {
 
-		final Element e1 = getElementAt(startOffset);
-		final Element e2 = getElementAt(endOffset);
-		if (e1 != e2) {
+		final Element surroundingElement = getElementAt(startOffset);
+		final Element elementAtEndOffset = getElementAt(endOffset);
+		if (surroundingElement != elementAtEndOffset) {
 			throw new IllegalArgumentException("Deletion from " + startOffset + " to " + endOffset + " is unbalanced");
 		}
 
 		final Validator validator = getValidator();
 		if (validator != null) {
-			final List<QualifiedName> seq1 = getNodeNames(e1.getStartOffset() + 1, startOffset);
-			final List<QualifiedName> seq2 = getNodeNames(endOffset, e1.getEndOffset());
+			final List<QualifiedName> seq1 = getNodeNames(surroundingElement.getStartOffset() + 1, startOffset);
+			final List<QualifiedName> seq2 = getNodeNames(endOffset, surroundingElement.getEndOffset());
 
-			if (!validator.isValidSequence(e1.getQualifiedName(), seq1, seq2, null, true)) {
+			if (!validator.isValidSequence(surroundingElement.getQualifiedName(), seq1, seq2, null, true)) {
 				throw new DocumentValidationException("Unable to delete from " + startOffset + " to " + endOffset);
 			}
 		}
@@ -140,16 +141,13 @@
 		// Grab the fragment for the undoable edit while it's still here
 		final DocumentFragment frag = getFragment(startOffset, endOffset);
 
-		fireBeforeContentDeleted(new DocumentEvent(this, e1, startOffset, endOffset - startOffset, null));
+		fireBeforeContentDeleted(new DocumentEvent(this, surroundingElement, startOffset, endOffset - startOffset, null));
 
-		Iterator<Node> iter = e1.getChildNodes().iterator();
-		if (e1 instanceof Element) {
-			iter = e1.getChildIterator();
-		}
+		final Iterator<Node> iter = surroundingElement.getChildIterator();
 		while (iter.hasNext()) {
 			final Node child = iter.next();
 			if (startOffset <= child.getStartOffset() && child.getEndOffset() < endOffset) {
-				iter.remove();
+				surroundingElement.removeChild(child);
 			}
 		}
 
@@ -157,7 +155,7 @@
 
 		final IUndoableEdit edit = undoEnabled ? new DeleteEdit(startOffset, endOffset, frag) : null;
 
-		fireContentDeleted(new DocumentEvent(this, e1, startOffset, endOffset - startOffset, edit));
+		fireContentDeleted(new DocumentEvent(this, surroundingElement, startOffset, endOffset - startOffset, edit));
 	}
 
 	public Element findCommonElement(final int offset1, final int offset2) {
@@ -830,7 +828,14 @@
 		return documentURI;
 	}
 
+	@Override
 	public String getBaseURI() {
 		return getDocumentURI();
 	}
+
+	@Override
+	public String getNodeType() {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java
index cb521bf..1abfe76 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentBuilder.java
@@ -56,7 +56,7 @@
 
 	private final NamespaceStack namespaceStack = new NamespaceStack();
 
-	private RootElement rootElement;
+	private Element rootElement;
 
 	private final String baseUri;
 	private String dtdPublicID;
@@ -105,7 +105,6 @@
 		document = new Document(content, rootElement);
 		document.setPublicID(dtdPublicID);
 		document.setSystemID(dtdSystemID);
-		rootElement.setDocument(document);
 	}
 
 	public void endElement(final String namespaceURI, final String localName, final String qName) {
@@ -151,7 +150,7 @@
 		}
 		Element element;
 		if (stack.isEmpty()) {
-			rootElement = new RootElement(elementName);
+			rootElement = new Element(elementName);
 			element = rootElement;
 		} else {
 			element = new Element(elementName);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentContentModel.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentContentModel.java
index 3ecbc67..8f7584b 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentContentModel.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/DocumentContentModel.java
@@ -38,11 +38,11 @@
 	public DocumentContentModel() {

 	}

 

-	public DocumentContentModel(final String baseUri, final String publicId, final String systemId, final RootElement rootElement) {

+	public DocumentContentModel(final String baseUri, final String publicId, final String systemId, final Element rootElement) {

 		initialize(baseUri, publicId, systemId, rootElement);

 	}

 

-	public void initialize(final String baseUri, final String publicId, final String systemId, final RootElement rootElement) {

+	public void initialize(final String baseUri, final String publicId, final String systemId, final Element rootElement) {

 		this.baseUri = baseUri;

 		this.publicId = publicId;

 		this.systemId = systemId;

diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
index b375a2a..2aa854a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
@@ -183,19 +183,6 @@
 		return elements;
 	}
 
-	@Override
-	public Document getDocument() {
-		Node root = this;
-		while (root.getParent() != null) {
-			root = root.getParent();
-		}
-		if (root instanceof RootElement) {
-			return ((Element) root).getDocument();
-		} else {
-			return null;
-		}
-	}
-
 	public String getLocalName() {
 		return name.getLocalName();
 	}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java
index c234c99..b0845ca 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java
@@ -60,6 +60,24 @@
 		return content.getText(getStartOffset(), getEndOffset() - getStartOffset());
 	}
 
+	public Document getDocument() {
+		return getDocument(this);
+	}
+
+	private static Document getDocument(final Node node) {
+		if (node instanceof Document) {
+			return (Document) node;
+		}
+		final Parent parent = node.getParent();
+		if (parent == null) {
+			return null;
+		}
+		if (parent instanceof Document) {
+			return (Document) parent;
+		}
+		return getDocument(parent);
+	}
+
 	public abstract String getNodeType();
 
 	public abstract String getBaseURI();
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Parent.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Parent.java
index ef389c2..a924f4d 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Parent.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Parent.java
@@ -25,8 +25,8 @@
 	}

 

 	public List<Node> getChildNodes() {

-		//		return Document.createNodeList(getContent(), getStartOffset() + 1, getEndOffset(), childNodes);

-		return Collections.unmodifiableList(children);

+		return Collections.unmodifiableList(Document.createNodeList(getContent(), getStartOffset() + 1, getEndOffset(), children));

+		// return Collections.unmodifiableList(children);

 	}

 

 	public Iterator<Node> getChildIterator() {

diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/RootElement.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/RootElement.java
deleted file mode 100644
index 1f74080..0000000
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/RootElement.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     John Krasnay - initial API and implementation
- *******************************************************************************/
-package org.eclipse.vex.core.internal.dom;
-
-import org.eclipse.core.runtime.QualifiedName;
-
-/**
- * The root element of a document. Keeps track of the document to which it is associated. Any element can find the
- * document to which it is associated by following its parents to this root. This would be done, for example, to notify
- * document listeners that the document has changed when the element changes.
- */
-public class RootElement extends Element {
-
-	private Document document;
-
-	public RootElement(final String localName) {
-		super(localName);
-	}
-
-	public RootElement(final QualifiedName qualifiedName) {
-		super(qualifiedName);
-	}
-
-	@Override
-	public Document getDocument() {
-		return document;
-	}
-
-	public void setDocument(final Document document) {
-		this.document = document;
-	}
-
-}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
index 7523e41..786c82e 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
@@ -12,8 +12,8 @@
 

 import org.eclipse.swt.widgets.Shell;

 import org.eclipse.vex.core.internal.dom.DocumentContentModel;

+import org.eclipse.vex.core.internal.dom.Element;

 import org.eclipse.vex.core.internal.dom.IWhitespacePolicy;

-import org.eclipse.vex.core.internal.dom.RootElement;

 import org.eclipse.vex.core.internal.widget.CssWhitespacePolicy;

 import org.eclipse.vex.ui.internal.VexPlugin;

 import org.eclipse.vex.ui.internal.config.DocumentType;

@@ -37,7 +37,7 @@
 	}

 

 	@Override

-	public void initialize(final String baseUri, final String publicId, final String systemId, final RootElement rootElement) {

+	public void initialize(final String baseUri, final String publicId, final String systemId, final Element rootElement) {

 		super.initialize(baseUri, publicId, systemId, rootElement);

 		final String mainDocumentTypeIdentifier = getMainDocumentTypeIdentifier();

 		documentType = getRegisteredDocumentType();

diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/SplitBlockElementHandler.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/SplitBlockElementHandler.java
index 8130bf1..53d5425 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/SplitBlockElementHandler.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/SplitBlockElementHandler.java
@@ -21,7 +21,6 @@
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.DocumentFragment;
 import org.eclipse.vex.core.internal.dom.Element;
-import org.eclipse.vex.core.internal.dom.RootElement;
 import org.eclipse.vex.core.internal.widget.IVexWidget;
 import org.eclipse.vex.ui.internal.swt.VexWidget;
 
@@ -39,7 +38,7 @@
 		Styles styles = widget.getStyleSheet().getStyles(element);
 		while (!styles.isBlock()) {
 			element = element.getParentElement();
-			if (element == null || element instanceof RootElement) {
+			if (element == null || element.getParent() instanceof Document) {
 				return; // we reached the root element which cannot be split 
 			}
 			styles = widget.getStyleSheet().getStyles(element);
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
index 950ba29..0da73cf 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
@@ -34,7 +34,7 @@
 import org.eclipse.vex.core.internal.dom.Document;
 import org.eclipse.vex.core.internal.dom.DocumentContentModel;
 import org.eclipse.vex.core.internal.dom.DocumentWriter;
-import org.eclipse.vex.core.internal.dom.RootElement;
+import org.eclipse.vex.core.internal.dom.Element;
 import org.eclipse.vex.core.internal.validator.WTPVEXValidator;
 import org.eclipse.vex.core.internal.widget.CssWhitespacePolicy;
 import org.eclipse.vex.ui.internal.VexPlugin;
@@ -128,7 +128,7 @@
 	}
 
 	private static Document createDocumentWithDTD(final DocumentType documentType, final String rootElementName) {
-		final RootElement root = new RootElement(rootElementName);
+		final Element root = new Element(rootElementName);
 		final Document result = new Document(root);
 		result.setPublicID(documentType.getPublicId());
 		result.setSystemID(documentType.getSystemId());
@@ -137,7 +137,7 @@
 
 	private static Document createDocumentWithSchema(final DocumentType documentType, final String rootElementName) {
 		final String defaultNamespaceUri = documentType.getPublicId();
-		final RootElement root = new RootElement(new QualifiedName(defaultNamespaceUri, rootElementName));
+		final Element root = new Element(new QualifiedName(defaultNamespaceUri, rootElementName));
 		root.declareDefaultNamespace(defaultNamespaceUri);
 
 		final WTPVEXValidator validator = new WTPVEXValidator(new DocumentContentModel(null, null, null, root));