Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Who's right - JDK 1.6 stax or WoodStox?

843834Mar 20 2007 — edited Mar 22 2007
Hi all...

I have a serious problem with switching between aforementioned technologies and I'm confused which one works properly. My case is easy - I have XML that starts like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE field-specification SYSTEM "http://xxx/dtd/field-specification.dtd">
And I have following naive code:
XMLInputFactory xmlif = XMLInputFactory.newInstance();
XMLStreamReader reader = xmlif.createXMLStreamReader(sourceReader);
Now using WoodStox it ends like:
com.ctc.wstx.exc.WstxIOException: xxx
	at com.ctc.wstx.sr.StreamScanner.throwFromIOE(StreamScanner.java:650)
	at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1071)
	at sk.bgs.swift.XMLUtils.prepareXmlReader(XMLUtils.java:159)
...
Caused by: java.net.UnknownHostException: xxx
And I need following line to tell WoodStox "please, ignore that DTD":
xmlif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
Now it works... if I switch to JDK 1.6, it works. If I drop Woodstox from classpath, using JDK 1.6 stax impl it stops to work with:
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,10]
Message: DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true.
So these versions are mutualy exclusive and I can't just compile it once. Not to mention that running the original example (usable with JDK 1.6 Stax Impl but with Woodstox in classpath) on 1.6 ends with stupid messages:
java.lang.IllegalStateException: Can't overwrite cause
	at java.lang.Throwable.initCause(Throwable.java:320)
	at com.ctc.wstx.compat.Jdk14Impl.setInitCause(Jdk14Impl.java:70)
This hardly tells you anything and it's also hard to claim that it is working like on JDK 1.5. ;-) However - here is final version of the code - that works in 1.5 with Woodstox and in 1.6 with both:
XMLInputFactory xmlif = XMLInputFactory.newInstance();
if (xmlif.getClass().getName().equals("com.ctc.wstx.stax.WstxInputFactory")) {
  xmlif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
}
XMLStreamReader reader = xmlif.createXMLStreamReader(sourceReader);
Ok, this is first story... the second one is also interesting. I have line in XML like this:
<prim name="y">[-A-Z0-9.,()/='+:?!"%&amp;*; ]</prim>
Now Woodstox has really no problem with it while with JDK 1.6 implementation just doesn't want to eat those entities and I'm pretty out of options how to make THIS working in both implementations. Not to say that I'm not sure which one is right.

But in this second case Woodstox is winner for me from logical point of view. Why is that & interpreted? Why reader.getText() returns only string up to % and stops there? There is no exception in implementation - of course - just my logic stops to work.

Have anyone run into similar problems?

Thanks for any hints and tips how to make such a things work in both cases.

Virgo47
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2007
Added on Mar 20 2007
5 comments
991 views