Hi, I've got a problem with the Batik DOM implementation. When I add an xlink:href attribute to my document, the xlink namespace is omitted, making the attribute invalid. I am using the following code:
SVGDOMImplementation impl = (SVGDOMImplementation) SVGDOMImplementation.getDOMImplementation(); AbstractDocument doc = (AbstractDocument) impl.createDocument(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_SVG_TAG, null); Element useElement = impl.createElementNS(doc, SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_USE_TAG); doc.getDocumentElement().appendChild(useElement); XLinkSupport.setXLinkHref( useElement, "somefile.svg#someid" ); StringWriter writer = new StringWriter(); try { DOMUtilities.writeDocument(doc, writer); System.out.println( writer.toString() ); } catch (IOException e) { e.printStackTrace(); } Running the above code with Batik 1.6 or 1.7 produces the following output: <?xml version="1.0" encoding="UTF-8"?> <svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.0"> <use xlink:actuate="onLoad" xlink:type="simple" xlink:show="embed" xmlns:xlink="http://www.w3.org/1999/xlink" href="somefile.svg#someid"/> </svg> Not only is the xlink namespace added a second time (it was already present in the root element), but the namespace prefix is missing in the href attribute. Since attributes, unlike elements, have no default namespace, the attribute is not a valid xlink:href attribute any more. When loading the serialized document, Batik correctly throws an error: The attribute "xlink:href" of the element <use> is required The funny thing is, when I just add the attribute and render the DOM tree without serializing it, the reference is accepted, GVT nodes are created and the referenced element shows up on the screen. I therefore suspect that some error occurs during serialization. Am I maybe missing something? What would be the correct way to add an xlink:href reference, or a use element with default attributes? What method is used to create the other xlink attributes that are lined up so nicely? Thanks for any insights. Regards, Gerrit -- http://www.fastmail.fm - Faster than the air-speed velocity of an unladen european swallow --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org