I'm having two problems with namespace support in Saxon 6.4.3:
1. Saxon doesn't tell JAXP parsers to be namespace-aware in getSourceParser() and getStyleParser() in TransformerFactoryImpl. I think Saxon should call setNamespaceAware(true) on the SAXParserFactory before creating the XMLReader.
2. Saxon essentially creates a level 1 DOM tree if you output to a DOMSource. I.e. DOMEmitter only calls createElement and friends, instead of createElementNS, etc. Hence all attempts to call getLocalName() et al fails totally.
I guess (2) isn't as big a deal as (1), but it took me quite a while to figure out, so it would be nice if the documentation mentioned this (if it doesn't already, and I am seriously visually challenged :-) ).
Cheers,
/dan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1. JAXP 1.0 introduced setNamespaceAware() because there was no way of telling a SAX1 parser that namespace processing was required. SAX2 has its own mechanisms for asking the parser for namespace processing, which Saxon uses; therefore I think that the JAXP method is now redundant.
2. Saxon tries to use only DOM features that all DOM implementations are obliged to support. I agree the documentation could mention this.
Mike Kay
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2001-09-17
1. No it doesn't :-)
The code snippet below doesn't print any element names, unless I call the fixSaxon() workaround (as you know, XMLReaders created with Class.forName() are supposed to be namespaceaware by default). As you can see, I'm testing against crimson (1.1.1).
2. Well, the DOM interfaces are such a mess, so I guess it's wise not to use them anyway. As far as I can see, the only safe way to use them (since "namespace awareness" is not guaranteed) is with code like:
Node node; // some node
String name = node.getLocalName();
if (name == null) {
name = node.getNodeName();
if (name.indexOf(':') != -1)
// do extremely tedious namespace processing
}
Anyway, here's the code for (1):
public class SaxonTest {
public static void main(String args[]) throws Exception {
I'm having two problems with namespace support in Saxon 6.4.3:
1. Saxon doesn't tell JAXP parsers to be namespace-aware in getSourceParser() and getStyleParser() in TransformerFactoryImpl. I think Saxon should call setNamespaceAware(true) on the SAXParserFactory before creating the XMLReader.
2. Saxon essentially creates a level 1 DOM tree if you output to a DOMSource. I.e. DOMEmitter only calls createElement and friends, instead of createElementNS, etc. Hence all attempts to call getLocalName() et al fails totally.
I guess (2) isn't as big a deal as (1), but it took me quite a while to figure out, so it would be nice if the documentation mentioned this (if it doesn't already, and I am seriously visually challenged :-) ).
Cheers,
/dan
1. JAXP 1.0 introduced setNamespaceAware() because there was no way of telling a SAX1 parser that namespace processing was required. SAX2 has its own mechanisms for asking the parser for namespace processing, which Saxon uses; therefore I think that the JAXP method is now redundant.
2. Saxon tries to use only DOM features that all DOM implementations are obliged to support. I agree the documentation could mention this.
Mike Kay
1. No it doesn't :-)
The code snippet below doesn't print any element names, unless I call the fixSaxon() workaround (as you know, XMLReaders created with Class.forName() are supposed to be namespaceaware by default). As you can see, I'm testing against crimson (1.1.1).
2. Well, the DOM interfaces are such a mess, so I guess it's wise not to use them anyway. As far as I can see, the only safe way to use them (since "namespace awareness" is not guaranteed) is with code like:
Node node; // some node
String name = node.getLocalName();
if (name == null) {
name = node.getNodeName();
if (name.indexOf(':') != -1)
// do extremely tedious namespace processing
}
Anyway, here's the code for (1):
public class SaxonTest {
public static void main(String args[]) throws Exception {
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.crimson.jaxp.SAXParserFactoryImpl");
TransformerFactory factory = TransformerFactory.newInstance();
// fixSaxon(factory);
Transformer trans = factory.newTransformer();
trans.transform(new StreamSource("src/test.xsl"),
new StreamResult(System.out));
}
static void fixSaxon(TransformerFactory factory) {
if (factory.getClass().getName().indexOf("saxon") != -1) {
try {
SAXParserFactory sax = SAXParserFactory.newInstance();
XMLReader reader = sax.newSAXParser().getXMLReader();
String className = reader.getClass().getName();
factory.setAttribute("http://icl.com/saxon/feature/sourceParserClass",
className);
factory.setAttribute("http://icl.com/saxon/feature/styleParserClass",
className);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/dan