DOM Validation "on-the-fly"

I have a (java) DOM object that adheres to an XML schema. I want to
manipulate it in code, but to ensure that the object still sticks to
the schema (ie, validation during the life-cycle of the DOM object, not
just upon initial parsing). Is this possible?

My investigation so far has revealed that DOM3 does provide validation
mechanisms for this, but no current parsers implement them. I've
picked up on something called the "post-schema-validation infoset"
(PSVI), but it looks like another full-blown API to learn - I just want
(ideally) a flag to indicate that I want the DOM object to reject
changes that cause it to become invalid.

I've also seem many other postings on this kind of question, but there
have never been any replies... Is this the kind of question that shows
I haven't grasped what XML and friends are all about and you're
laughing at my lack of understanding (I am new to this and am trying to
teach myself)? Should I really have another DOM object with the XSD
document in and use that to manually validate the other object?

Advertisements

> I have a (java) DOM object that adheres to an XML schema. I want to
> manipulate it in code, but to ensure that the object still sticks to
> the schema (ie, validation during the life-cycle of the DOM object, not
> just upon initial parsing). Is this possible?

Java 1.5 allows you to (re)validate a document against a schema by using
the javax.xml.validation namespace with SchemaFactory, Schema, Validator
objects and the validate method of Validator.
I don't see any features in there however to find out whether a certain
change is allowed in the way DOM Level 3 validation supports it.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!