• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

encoding attribute

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic