Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Validating parsed XML document against XML-schema

Thread view: 
TKok - 07 Dec 2005 16:53 GMT
*PROBLEM: how to validate parsed XML document against (parsed) XML-schema.

*IN: XML document as org.w3c.dom.Document, XML-schema as stream

*OUT: information if document is valid against schema. If document is not
valid DETAILED information about ALL errors (especially: node that caused
problem).

*Additional information:

-         validation is performed quite often,

-         XML-document object is changed quite often,

-         XML-Schema is fixed.

-         XML-document doesn't contain information about related XML-schema
(attr xsi:noNamespaceSchemaLocation)

-         XML-Schema is available as file only when the application starts.
It means that schema can be loaded from a file only once.

-         must works in Java1.4+

I've tried to implement it using JAXP:

//app start

SchemaFactory schemaFactory =

           SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Source schemaSource = new StreamSource(new File(schemaFile));

Schema schema = schemaFactory.newSchema(schemaSource);

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(xmlFile);

//document is being changed usign .addChild etc.

//

Validator validator = schema.newValidator();

validator.setErrorHandler(new SimpleErrorHandler());

validator.validate(new DOMSource(document));

Unfortunately org.xml.sax.ErrorHandler gets only SAXParseException which
doesn't constant information about node that caused the problem.

Is there any other way to validated DOM-document?
Rodrigo Zechin - 08 Dec 2005 14:01 GMT
Well. I use XmlBeans...
http://xmlbeans.apache.org/
I'ts quite faster than DOM, and offers XSD validation.

Zechin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.