Standard DOM |
Sparta DOM |
import import org.w3c.dom.* |
import com.hp.hpl.sparta.* |
d = DocumentBuilderFactory .newInstance() .newDocumentBuilder()
.newDocument() |
d=new Document() |
Sparta uses concrete classes |
e = d.createElement(tagName) |
e = new Element(tagName) |
ditto |
t = d.createTextNode(string) |
t = new Text(string) |
ditto |
e = d.getDocumentElement()
e = (Element)document.getFirstChild() |
e = d.getDocumentElement() |
The W3C provides two different ways of getting the same thing. Sparta
provides just one way. |
e.getTagName()
e.getNodeName() |
e.getTagName() |
ditto |
t.getData()
t.getNodeValue() |
t.getData() |
ditto |
if(n.getNodeType()==Node.ELEMENT_NODE) |
if(n instanceof Element) |
the W3C DOM
is language independent; with Sparta you can use Java type info |
NamedNodeMap
attrs = e.getAttributes() |
Enumeration attrNames = e.getAttributeNames() |
Sparta attributes are not a Node sub-class; instead an element has
a set of String name-value pairs. |
e.getAttributes().getNamedItem("foo") |
e.getAttribute("foo") |
ditto |
e.getElementsByTagName(tagName) |
e.xpathSelectElements("//"+tagName) |
SAXException |
DOMException |
d = DocumentBuilderFactory .newInstance() .newDocumentBuilder()
.parse(file) |
d = Parser.parse(file) |
DOMSource(d) |
DOMSource(DocumentImpl.wrapper(d)) |
To use Sparta with classes such as [javax.xml.transform.dom.DOMSource]
which expect W3C documents use the wrapper method of [hp.hpl.agile.thermopylae.DocumentImpl]
to covert from Sparta to W3C. |