You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Andy Jefferson <an...@ajsoft.net> on 2004/04/01 19:57:01 UTC

DOM : Obtaining encoding from an XML Doc

Hi,

I'm reading in an XML doc (with JDK 1.4.2) and want to get hold of the
document encoding 'value'. I've currently got a URL and I'm reading it as
per

docElement = builder.parse(url.openStream()).getDocumentElement();

Looking through the various methods on Document etc, I see nothing like
getInputEncoding(), getEncoding, etc (I see these are available in JDK 1.5
- DOM level 3). Its presumably available somewhere with JDK 1.4.2.
Do I have to do a getElementsByTagName("encoding") from some Node ?

How do I get the encoding ?


TIA
-- 
Andy


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: DOM : Obtaining encoding from an XML Doc

Posted by Martin Vysny <vy...@sozo.fns.uniba.sk>.
Andy Jefferson wrote:

>Looking through the various methods on Document etc, I see nothing like
>getInputEncoding(), getEncoding, etc (I see these are available in JDK 1.5
>- DOM level 3). 
>
You can use that DOM3 function by casting Document to Xerces's 
DocumentImpl class in J1-4-2 (actually, you can access some new DOM3 
functions this way, casting Node to NodeImpl etc.). DOM2 has no such 
function, AFAIK. When you'll start to use J1-5, just remove this cast
Martin Vysny

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: DOM : Obtaining encoding from an XML Doc

Posted by Joseph Kesselman <ke...@us.ibm.com>.



If you have a Level 2 DOM, there is no portable way to retrieve the
original encoding name. This was introduced in DOM Level 3, which is
currently a Proposed Recommendation -- ie, it's believed to be stable but
has not yet been officially approved/adopted by the W3C.

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org