Hi,
Cameron McCormack wrote:
Hi Paul.
Paul Wellner Bou:
So why are single quotes ' within attributes replaced with their entity?
Can I prevent them from beeing replaced?
I doubt that you can prevent them from being replaced without modifying
Batik. As with the issue you raised earlier, it is perfectly fine for
an XML serialisation to use numeric character references and entity
references like this (i.e., it’s well formed XML).
In the example below, it’s true that the apostrophes need not be
replaced with entities inside double-quoted attributes. I’m not sure if
the serialisation code sometimes uses double-quoted attributes and
sometimes single-quoted attributes; if it does, then it may use '
unconditionally just because it is simpler to do so. But if it’s usign
double-quoted attributes all the time, then I agree it’s better if it
didn’t use '.
Can you submit a small, standalone program that demonstrates the
problem?
Of course. The SVG:
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<text font-size="8" font-family="'ArialNarrow-Bold'"">Text</text>
</svg>
The Java Code:
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.util.XMLResourceDescriptor;
import org.w3c.dom.Document;
public class BatikTest
{
public static void main(String[] args)
{
try
{
File sourcefile= new File("test.svg");
String parser= XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f= new SAXSVGDocumentFactory(parser);
String uri= sourcefile.toURI().toString();
Document doc= f.createDocument(uri);
OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8");
SVGGraphics2D svgGenerator = new SVGGraphics2D(doc);
svgGenerator.stream(doc.getDocumentElement(), osw);
osw.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
I know that it is technically correct replacing it. But why it should?
It may have a reason why someone wants it replaced or not. And if there
is no need to replace something, I think it shouldn't do it. Or it
should be at least configurable.
And why is batik omitting the last character if it has to do something
with entities? For example:
>
I don’t think that’s a known bug, no, but it does look like a bug. As
above, can you provide a test case?
Regarding this I found my error. Not on the batik side. I implemented my
own java.io.writer and I catched the string in the buffer using new
String(cbuf).substring(off, len) and not String.valueOf(cbuf, off, len);
in the overriding write(char[] cbuf, int off, int len) method. Sorry.
Regards
Paul.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]