Java Reference
In-Depth Information
putting it into a method in the Element class that you call with the appropriate XML element name as an
argument:
protected org.w3c.dom.Element createPointTypeElement(Document doc,
String name,
String xValue,
String yValue) {
org.w3c.dom.Element element = doc.createElement(name);
Attr attr = doc.createAttribute("x");
// Create attribute x
attr.setValue(xValue);
// and set its value
element.setAttributeNode(attr);
// Insert the x attribute
attr = doc.createAttribute("y");
// Create attribute y
attr.setValue(yValue);
// and set its value
element.setAttributeNode(attr);
// Insert the y attribute
return element;
}
Directory "Sketcher reading and writing XML"
This creates an element with the name specified by the second argument, so you can use this in another
method in the Element class to create a node for a <position> element:
// Create the XML element for the position of a sketch element
protected org.w3c.dom.Element createPositionElement(Document doc) {
return createPointTypeElement(doc, "position",
String.valueOf(position.x),
String.valueOf(position.y));
}
Directory "Sketcher reading and writing XML"
You are able to create <endpoint> or <point> nodes in the same way in methods that you implement in
the subclasses of Element .
You can create a <bounds> element like this:
protected org.w3c.dom.Element createBoundsElement(Document doc) {
org.w3c.dom.Element boundsElement = doc.createElement("bounds");
Search WWH ::




Custom Search