xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Beton, Richard" <richard.be...@roke.co.uk>
Subject Attributes and Namespaces with Batik's DOM implementation.
Date Thu, 30 Sep 2004 14:49:40 GMT
If I have a <desc> element, I should be able to set and get the 
xml:space attribute using

    String space = desc.getAttributeNS( XMLConstants.XML_NAMESPACE_URI, 
"space" );
    desc.setAttributeNS( XMLConstants.XML_NAMESPACE_URI, "space", 
"preserve" );

However, I'm getting some unexpected behaviour when I write my document 
to a file and read it back in.  Having set the xml:space attribute as 
above, the SVG document contains
    <desc space="preserve">blah</desc>
This is incorrect: the "xml:" namespace prefix is missing from the space 

If instead I use the following incorrect code:
    desc.setAttributeNS( null, "xml:space", "preserve" );
then the output file is written correctly.

This odd behaviour seems to happen only with some namespaced-attributes, 
not all.  The two I've noticed are xml:space and xlink:href, and these 
show problems only intermittently.  Is this a bug in Batik's DOM?  (I'm 
using v1.5.1.)  Or have I omitted something?

I noticed there has been a related bug filed;


Here's a more complete exceprt of my test code

    public void addContent ()
        SVGOMDocument document = (SVGOMDocument) getDocument();
        Element svg = document.getDocumentElement();
        SVGDOMImplementation impl = (SVGDOMImplementation)
        Element defs = impl.createElementNS( document,
SVGConstants.SVG_DEFS_TAG );
        defs.setAttributeNS( null, "id", "defs1" );
        svg.appendChild( defs );

        Element desc = impl.createElementNS( document,
SVGConstants.SVG_DESC_TAG );
        GenericText t1 = new GenericText( "two line\ndescription", 
document );
        desc.appendChild( t1 );
        desc.setAttributeNS( null, "id", "desc1" );
        desc.setAttributeNS( XMLConstants.XML_NAMESPACE_URI, "space", 
"preserve" );
        svg.appendChild( desc );

        Element a = impl.createElementNS( document,
SVGConstants.SVG_A_TAG );
        GenericText t2 = new GenericText( "hello", document );
        a.appendChild( t2 );
        a.setAttribute( "id", "a1" );
        a.setAttributeNS( XMLConstants.XLINK_NAMESPACE_URI, "href", 
"nowhere" );
        a.setAttributeNS( XMLConstants.XLINK_NAMESPACE_URI, "type", 
"simple" );
        svg.appendChild( a );


Visit our website at www.roke.co.uk

Roke Manor Research Ltd, Roke Manor, Romsey, Hampshire SO51 0ZN, UK.

The information contained in this e-mail and any attachments is confidential to
Roke Manor Research Ltd and must not be passed to any third party without
permission. This communication is for information only and shall not create or
change any contractual relationship.

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

View raw message