• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

encoding attribute

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

Hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic