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 Stam <ka...@ics.forth.gr> on 2004/05/28 11:48:43 UTC

On the fly validation of DOM creation

Hello! I am using Apache Xerces (from JAXP) to create DOM documents. I 
do not want to create them parsing XML documents but rather I want to 
create "empty" documents an add nodes "manually". Each time I add a node 
to the DOM I want to validate it in respect to a certain XML Schema. Is 
it possible? (I know that validation can be done when creating a DOM 
from an XML document)

Thanx in advance

Stam

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


Re: On the fly validation of DOM creation

Posted by Neil Delima <nd...@ca.ibm.com>.




Martin Vysny <vy...@sozo.fns.uniba.sk> wrote on 05/28/2004 06:07:19 AM:

> Stam wrote:
>
> > Hello! I am using Apache Xerces (from JAXP) to create DOM documents. I
> > do not want to create them parsing XML documents but rather I want to
> > create "empty" documents an add nodes "manually". Each time I add a
> > node to the DOM I want to validate it in respect to a certain XML
> > Schema. Is it possible? (I know that validation can be done when
> > creating a DOM from an XML document)
> >
> >

> It is possible, although it is not so easy. First, the XML may not be
> valid after adding just one node, for example when you have rule as: E->
> A.B | nothing (like E can contain both A and B, or none of them), then
> you must add both A and B. To validate a document you may use XML Schema
> API (XSModel, XSLoader, XS*), or just serialize the document and then
> parse again :-). However when you use the API, you may find some hints
> how the document should be edited correctly.
> Sincerely,
> Martin Vysny
>

It should also be possible to do this with JAXP (1.2) and DOM Level 3's
DOMConfiguration [2] and normalizeDocument [3] features but it's going to
be costly.   Create your document using JAXP's DocumentBuilders and add
nodes as required.  Using DOM Level3 obtain the Document's DOMConfiguration
and set the "schema-type," "schema-location" and "validate"
DOMConfiguration parameters and invoke normalizeDocument to validate your
document.

[1] http://xml.apache.org/xerces2-j/faq-dom.html#faq-2
[2]
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#DOMConfiguration
[3]
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-normalizeDocument


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


Re: On the fly validation of DOM creation

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

> Hello! I am using Apache Xerces (from JAXP) to create DOM documents. I 
> do not want to create them parsing XML documents but rather I want to 
> create "empty" documents an add nodes "manually". Each time I add a 
> node to the DOM I want to validate it in respect to a certain XML 
> Schema. Is it possible? (I know that validation can be done when 
> creating a DOM from an XML document)
>
> Thanx in advance
>
> Stam
>
It is possible, although it is not so easy. First, the XML may not be 
valid after adding just one node, for example when you have rule as: E-> 
A.B | nothing (like E can contain both A and B, or none of them), then 
you must add both A and B. To validate a document you may use XML Schema 
API (XSModel, XSLoader, XS*), or just serialize the document and then 
parse again :-). However when you use the API, you may find some hints 
how the document should be edited correctly.
Sincerely,
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