I am not able to read an XML file with the following error:
at org.apache.xerces.impl.io.UTF8Reader.invalidByte(Unknown Source)
at org.apache.xerces.impl.io.UTF8Reader.read(Unknown Source)
at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
at org.apache.xerces.impl.XMLEntityScanner.skipChar(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache..xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces..parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
The header of state.xml is as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html (View Source for full doctype...)>
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">
Any assistance would be much appreciated.
The document is encoded in UTF-8, but you are reading it using a Reader which doesn't use UTF-8. It uses some other encoding, which one I don't really care. Don't use a Reader at all. Pass an InputStream to the parser and let it deal with the encoding issues.
Joined: Oct 20, 2006
By replacing the FileReader with InputStream the following codes as suggested has finally able to read and transformed state.xml to state.html but only when there is an Internet Online connection:
[color=red][b]javax.xml.transform.TransformerException: org.jdom.JDOMException: DTD parsing error: www.w3.org
Caused by: org.jdom.JDOMException: DTD parsing error: www.w3.org
... 3 more[/b][/color]
It appears that the transformation process is trying to validate DTD even though I have turned validation off during parsing. Can you confirm whether the validation attempt is occurring during parsing or transformation step? And how to prevent it from recurring?
No, it isn't trying to validate the DTD. It is trying to read the DTD. You seem to be under the impression that DTDs are just for validation, but they perform several other functions. Entity definitions, for one. If the DTD contains an entity definition you want that to be applied to your document, or it won't parse correctly. That's why you can't tell the parser to ignore the DTD entirely.
You can use an XML Catalog to tell the parser to look for a local copy of the DTD, or you can use an EntityResolver which you attach to your parser.
Joined: Oct 20, 2006
Thanks for your suggestion.
Looks like I have got a bit of home work to be done.
Will try out both XML Catolog and Entity Resolver to see which is more suitable for me.
subject: java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence in JDOM SaxBuilder