adoptNode method doesn't create a document. Please read docs on this method and what Elena has said more carefully

Gloria Yang wrote:
Dear Elena:

    Thanks for your help.
    Now I am trying to use DOM3 normalizeDocument to do my job.
    I still have some problems.
    I try to use AdoptNode to make a new Document object with an element
which to be validated.

    a snippet code is as below:

    1.    Element worknode = doc.getElementById("four.worker");
    2.    Document newdoc =
(org.apache.xerces.dom.DocumentImpl)doc.adoptNode((Node)worknode);
    3.    ((Document)newdoc).normalizeDocument();

    but in line 2, exception occurs : java.lang.ClassCastException

    How should I do? Could you give me some suggestion & sample code?
    Thank you very much.

Best Regards
Gloria


----- Original Message ----- 
From: "Elena Litani" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 25, 2003 11:40 PM
Subject: Re: How to validate an element rather than the whole xml document


  
I need to validate an element aganist schema rather than the
whole document.
    

Currently, it is not possible to revalidate a singe element within the
DOM tree.
The best way of achieving what you want is using DOM Level 3
normalizeDocument that allows to revalidate a document in memory [1].
You can setup the schema on the <key> element using xsi:schemaLocation
attributes and register your own error handler that will ignore errors
for <SOAPENV:Envelope>, <SOAPBODY:Body> elements (the validator will
complain that declaration for those is not found).

If you really want to revalidate a single node.. you can create a new
document, use adoptNode to move a single element you want to revalidate
to a new document, use DOM L3 normalizeDocument on the new document to
revalidate just that single node. Then, if needed, you can use adoptNode
again to move back the element to the original document.


[1] http://xml.apache.org/xerces2-j/faq-dom.html#faq-7

Hope it helps,
  

--

Maksym Kovalenko
Software Engineer
Marketswitch Corporation
http://www.marketswitch.com
108 Powers Court, Suite 225
Dulles, VA 20166
Phone: +1 (703) 444-6750 ext. 302
Fax: +1 (703) 444-6812

Reply via email to