Dear List,
I'm having problems with using EntityReferences as the value of a
style attribute. I would like to create the following line in an SVG
document:
<rect x="35" y="70" width="315" style="&st1;" height="50" />
(I am creating this SVG document de novo, so I don't know how to
create an !ENTITY that will correspond to the &st1;, but I'm prepared
to work around that with a non-DOM API solution (since it is my
[mis-?]understanding that Entities are currently read-only). If
anyone has suggestions here, that would be great also.)
I thought I should do something like this:
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
public static final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
document = domImpl.createDocument(svgNS, SVG_SVG_TAG, null);
Element svgRoot = document.getDocumentElement();
...
Element rect = document.createElementNS(svgNS, SVG_RECT_TAG);
rect.setAttributeNS(null, SVG_X_ATTRIBUTE, "35");
...
Attr styleAttr = document.createAttribute(SVG_STYLE_ATTRIBUTE);
styleAttr.setValue("&st1;");
rect.setAttributeNode(styleAttr);
svgRoot.appendChild(rect);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
svgGenerator.stream(svgRoot, out, false);
But that turns the ampersand into an & and gives me:
<rect x="35" y="70" width="315" style="&st1;" height="50" />
I saw in the description of the setAttributeNS method of the Element
interface that it says:
"This value is a simple string; it is not parsed as it is being set.
So any markup (such as syntax to be recognized as an entity
reference) is treated as literal text, and needs to be appropriately
escaped by the implementation when it is written out. In order to
assign an attribute value that contains entity references, the user
must create an Attr node plus any Text and EntityReference nodes,
build the appropriate subtree, and use setAttributeNodeNS or
setAttributeNode to assign it as the value of an attribute. "
..but I can't figure out exactly what I'm supposed to do. I tried to
create an EntityReference object but was unsuccessful in attaching it
to anything (not that I knew to what I should be attaching it).
I want to use EntityReferences because 1) I'm going to have a style
repeated several hundred times in a document and want to conserve
space in my resulting .svg file and 2) I would like to be able to
change that style very easily (by just changing the Entity
definition).
Any help with this would be appreciated.
Thanks...
Ezra Jennings
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]