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 Gloria Yang <gl...@itri.org.tw> on 2003/10/01 11:45:22 UTC

Re: How to validate an element rather than the whole xml document

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" <el...@ca.ibm.com>
To: <xe...@xml.apache.org>
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,
-- 
Elena Litani / IBM Toronto

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


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


Re: How to validate an element rather than the whole xml document

Posted by Gloria Yang <gl...@itri.org.tw>.
Yes, Thanks for all your help.

I can validate a single element now.
But I still have some questions.

1. Does DOM3 using GrammarPool?

2. when I validate document, I can specify only one schema using config.setParameter("schema-location","xxxx");
    How to specify serveral schema locations ?

    for example, if I want to validate a document below:
   
  <person id="four.worker">
    <name><family>Worker</family> <given>Four</given></name>
    <email>four@foo.com</email>
    <link manager="Big.Boss"/>
  </person>
  
 I hava to specify the schema of person and XMLSchema.

 How should I do?

    Thank you very much.

Gloria
 
----- Original Message ----- 
From: Maksym Kovalenko 
To: xerces-j-user@xml.apache.org 
Sent: Wednesday, October 01, 2003 9:41 PM
Subject: Re: How to validate an element rather than the whole xml document



----- Original Message ----- 
From: "Elena Litani" <el...@ca.ibm.com>
To: <xe...@xml.apache.org>
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,
  

-- 


--------------------------------------------------------------------------------

Re: How to validate an element rather than the whole xml document

Posted by Maksym Kovalenko <mk...@marketswitch.com>.
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" <el...@ca.ibm.com>
>To: <xe...@xml.apache.org>
>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 <http://www.marketswitch.com/>
108 Powers Court, Suite 225
Dulles, VA 20166
Phone: +1 (703) 444-6750 ext. 302
Fax: +1 (703) 444-6812