DOM level 3 specs add new methods in Document interface to get standalone and encoding attributes from xml declaration tag how is it possible in SAX ?
Test 094, IBM WID 6.0 cert
SCJP 1.2
SCBCD 1.3 Beta
SCWCD 1.4 Beta
SCMAD Beta
SCDJWS Beta
KS
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Hi Kalpesh, I don't think this possibility exists in SAX right now and that it will be planned for future releases... The question is really why would you need such feature to exist in SAX? Why would you need to access the standalone or encoding attributes of the XML prologue when parsing a XML file? If you absolutely need to doing this without DOM level3, you may open the document yourself and parse the xml decl. This shouldn't be too hard as the xml decl grammar is very simple. The only tricky bit is managing to read with the correct encoding as caracters are 1 or 2 bytes wide (for the UTF-16 familly of charsets). Now, if you now that your XML documents are not using wide charsets, you can assume you're always having 1 byte per char. Cheers
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
OK, I found a way of doing this is you're using Xerces as your favourite SAX parser. Please note that the following code is based on the actual implementation of Xerces and will not work if you're using a different parser.
The contents of the xmlDeclTest.xml file is as follows:
As expected, when running the XMLDeclSAXParser class, the output gives: