xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ezra Jennings" <e...@wi.mit.edu>
Subject Entity References
Date Wed, 12 Sep 2001 22:53:45 GMT
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 

<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 = 
     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);

     SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
     BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
     svgGenerator.stream(svgRoot, out, false);

But that turns the ampersand into an &amp; and gives me:

<rect x="35" y="70" width="315" style="&amp;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 

Any help with this would be appreciated.

Ezra Jennings

To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org

View raw message