Search in sources :

Example 1 with Range

use of org.w3c.dom.ranges.Range in project webtools.sourceediting by eclipse.

the class TestRangeCompare method testRangeCompare.

public void testRangeCompare() throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    model.getStructuredDocument().set(decl);
    Document document = model.getDocument();
    // $NON-NLS-1$
    Element root = document.createElement("parent");
    document.appendChild(root);
    // $NON-NLS-1$
    Element child = document.createElement("child");
    root.appendChild(child);
    // $NON-NLS-1$
    child.appendChild(document.createElement("child1-1"));
    // $NON-NLS-1$
    Text textnode = document.createTextNode("Text Node");
    root.appendChild(textnode);
    // $NON-NLS-1$
    NodeList children = root.getElementsByTagName("child");
    Range range = ((DocumentImpl) document).createRange();
    range.setEnd(children.item(0), 1);
    Range sourceRange = ((DocumentImpl) document).createRange();
    sourceRange.setEnd(textnode, 0);
    int result = range.compareBoundaryPoints(Range.END_TO_END, sourceRange);
    assertEquals(-1, result);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) Range(org.w3c.dom.ranges.Range) DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

Aggregations

DocumentImpl (org.eclipse.wst.xml.core.internal.document.DocumentImpl)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1 Text (org.w3c.dom.Text)1 Range (org.w3c.dom.ranges.Range)1