#517 Bug in DOMWriter: setAttributeNS calls (with patch)

v8.7.1
closed
nobody
5
2012-10-08
2006-05-07
No

Due to recent changes in Apache FOP users have reported
problems with SAXON 8. That lead me to a bug in version
8.7.1. net.sf.saxon.dom.DOMWriter.attribute() sends the
default namespace as empty strings and not "null" as is
specified for the W3C DOM (although maybe not as
prominently as would be expected). But clarifications
on that can be found on the net.

Apache Batik fixed their DOM implementation to accept
both empty strings and null values for the namespace
URI but it would be good if the bug were fixed in
SAXON, too, especially since Batik won't be able to do
a release very quickly.

To fix the bug in SAXON please change the attribute()
method in DOMWriter like this:

public void attribute (int nameCode, int typeCode,

CharSequence value, int locationId, int properties)
throws XPathException {
String qname = namePool.getDisplayName(nameCode);
String uri = namePool.getURI(nameCode);
//--change starts here
if ("".equals(uri)) {
uri = null;
}
//--change ends here
try {
Element element = (Element)currentNode;
element.setAttributeNS(uri, qname,
value.toString());
} catch (DOMException err) {
throw new DynamicError(err);
}
}

More details about the problem can be found here:
http://xmlgraphics.apache.org/fop/faq.html#svg-attribute-required
http://www.nabble.com/fop-trunk-svg-problems-t1177182.html
http://www.nabble.com/REGRESSION%3A-embedded-SVG-support-in-0.92beta-compared-to-0.91beta-t1531627.html

Discussion

  • Michael Kay

    Michael Kay - 2006-05-10

    Logged In: YES
    user_id=251681

    This change appears to be correct, and has been applied to
    the source. Please note also that the same change should be
    made to the call on createElementNS on line 103 of the same
    module.

    It's not obvious to me why this bug should occur with Saxon
    8.7 and not with Saxon 8.6 - the code is identical.

    In future, please check with me before posting a patch here:
    I want users to know that before a bug or patch is posted
    here, there is a high level of confidence that it is correct.

     
  • Jeremias Märki

    Jeremias Märki - 2006-05-11

    Logged In: YES
    user_id=225352

    I'm sorry for the trouble. I was doing this for the benefit
    of FOP's users and I didn't want to spend too much time. So
    I may have gone over this a little too quickly.
    With "Saxon 8" I did not suggest that anything's different
    with 8.6 concerning this bug. I only tested with 8.7.1. The
    original bug report referred to "Saxon 8" (whatever that
    meant). Thanks for handling this so quickly. FOP's users
    will be thankful.