File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes How to validate a DOM object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to validate a DOM object ?" Watch "How to validate a DOM object ?" New topic

How to validate a DOM object ?

JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Hi all,
I have a DOM object which contains a xml document and a reference to its xsd.
I would like to validate the DOM against the XSD it contains.
The only way I found so far is :
- serialize the DOM
- parse the dom activating validation.
Is there another way to do it ?
Does not sound like a really efficient method, no ? I parse a document which has already been parsed !!

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Unfortunately this is only possible if you are in compliance with DOM Level 3 core specs that supports iterative load-validate-change-save operations and DOM events.
If you are using the new version of Xerces ie., Xerces2-J from Apache and DOM Level 3 compliant namespace, you may be able to use DOMConfig to validate the document in memory. Checkout this article for more details.
[ May 07, 2003: Message edited by: Ajith Kallambella ]

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Thanks Ajith,
That's what I thought.
You confirmation will help me saving a lot of time in research
I agree. Here's the link:
subject: How to validate a DOM object ?
It's not a secret anymore!