We are using javax.xml.transform.Transformer for encoding and decoding xml. Encoding is done without any errors, but when decoding exi we got exception :
ERROR: ''
javax.xml.transform.TransformerException: java.lang.NullPointerException
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:755)
When there is GrammarOptions.addNS(go) option used, exception is :
org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
this code snippet shows how encoding is done :
final Transmogrifier transmogrifier = new Transmogrifier();
transmogrifier.setAlignmentType(AlignmentType.bitPacked);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
transmogrifier.setGrammarCache(getGrammarCache());
transmogrifier.setOutputStream(out);
transmogrifier.encode(new InputSource(new ByteArrayInputStream(toString(xml, false).getBytes())));
out.flush();
return out.toByteArray();
code snippet for decoding :
try(ByteArrayInputStream in = new ByteArrayInputStream(input)) {
final EXIReader reader = new EXIReader();
reader.setAlignmentType(AlignmentType.bitPacked);
grammarCache = getGrammarCache();
reader.setGrammarCache(grammarCache);
final SAXTransformerFactory transformerFactory
= (SAXTransformerFactory) TransformerFactory.newInstance();
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
final TransformerHandler handler = transformerFactory.newTransformerHandler();
handler.setResult(domResult);
reader.setContentHandler(handler);
reader.parse(new InputSource(in));
}
code snippet grammar options used :
private static GrammarCache getGrammarCache() {
short go = GrammarOptions.DEFAULT_OPTIONS;
// This option on or off, nagasena still fails
go = GrammarOptions.addNS(go);
return new GrammarCache(null, go);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I discovered so far that javax.xml.transform.TransformerException: java.lang.NullPointerException is caused by Transmogrifier$SAXEventHandler#verifyPrefix in which new Locator is created using copy constructor with m_locator as argument which is null. There seems to be issue related to uri extracted from prefix.
Last edit: Martin Bobak 2014-04-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Test fails when Transformer javax.xml.transform.Transformer is used for encoding exi. Here is code snippet how we are using it :
final Transmogrifier transmogrifier = new Transmogrifier();
transmogrifier.setAlignmentType(AlignmentType.bitPacked);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
transmogrifier.setGrammarCache(getGrammarCache());
transmogrifier.setOutputStream(out);
final Transformer transformer = saxTransformerFactory.newTransformer();
transformer.transform(new DOMSource(xml), new SAXResult(transmogrifier.getSAXTransmogrifier()));
byte[] bts = out.toByteArray();
Last edit: Martin Bobak 2014-04-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In your initial report, you said "Encoding is done without any errors, but when decoding exi we got exception". That's what I investigated. Also, the test I implemented was about the decoding, which I verified works. Was that statement bogus?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We are using javax.xml.transform.Transformer for encoding and decoding xml. Encoding is done without any errors, but when decoding exi we got exception :
ERROR: ''
javax.xml.transform.TransformerException: java.lang.NullPointerException
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:755)
When there is GrammarOptions.addNS(go) option used, exception is :
org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
this code snippet shows how encoding is done :
final Transmogrifier transmogrifier = new Transmogrifier(); transmogrifier.setAlignmentType(AlignmentType.bitPacked); final ByteArrayOutputStream out = new ByteArrayOutputStream(); transmogrifier.setGrammarCache(getGrammarCache()); transmogrifier.setOutputStream(out); transmogrifier.encode(new InputSource(new ByteArrayInputStream(toString(xml, false).getBytes()))); out.flush(); return out.toByteArray();code snippet for decoding :
try(ByteArrayInputStream in = new ByteArrayInputStream(input)) { final EXIReader reader = new EXIReader(); reader.setAlignmentType(AlignmentType.bitPacked); grammarCache = getGrammarCache(); reader.setGrammarCache(grammarCache); final SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance(); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setNamespaceAware(true); final TransformerHandler handler = transformerFactory.newTransformerHandler(); handler.setResult(domResult); reader.setContentHandler(handler); reader.parse(new InputSource(in)); }code snippet grammar options used :
private static GrammarCache getGrammarCache() { short go = GrammarOptions.DEFAULT_OPTIONS; // This option on or off, nagasena still fails go = GrammarOptions.addNS(go); return new GrammarCache(null, go); }Hi,
Can you send me the XML and schema files that were used?
taki
This is xml used for testing :
it is generated from Element object constructed by method getDom :
I discovered so far that javax.xml.transform.TransformerException: java.lang.NullPointerException is caused by Transmogrifier$SAXEventHandler#verifyPrefix in which new Locator is created using copy constructor with m_locator as argument which is null. There seems to be issue related to uri extracted from prefix.
Last edit: Martin Bobak 2014-04-16
I added a test case "testToDOM_01" in XmlSerializationTest.java.
The test case basically does what you described.
Can you retrieve the source and tests, and run the unit tests?
You can export nagasena by:
$ svn export https://svn.code.sf.net/p/openexi/code/trunk/nagasena
Unit tests can be run by:
$ ant clean; ant test
Test fails when Transformer javax.xml.transform.Transformer is used for encoding exi. Here is code snippet how we are using it :
final Transmogrifier transmogrifier = new Transmogrifier(); transmogrifier.setAlignmentType(AlignmentType.bitPacked); final ByteArrayOutputStream out = new ByteArrayOutputStream(); transmogrifier.setGrammarCache(getGrammarCache()); transmogrifier.setOutputStream(out); final Transformer transformer = saxTransformerFactory.newTransformer(); transformer.transform(new DOMSource(xml), new SAXResult(transmogrifier.getSAXTransmogrifier())); byte[] bts = out.toByteArray();Last edit: Martin Bobak 2014-04-23
In your initial report, you said "Encoding is done without any errors, but when decoding exi we got exception". That's what I investigated. Also, the test I implemented was about the decoding, which I verified works. Was that statement bogus?
Please give precise description to your report next time.
I believe I fixed this issue in the latest Nagasena.
I'm sorry for misleading you. My bad. But error happend during decoding only when exi was encoded using Transformer.
Last edit: Martin Bobak 2014-04-24
Thanks for finding the issue.