Click here to Skip to main content
12,825,743 members (37,554 online)
Rate this:
Please Sign up or sign in to vote.
See more: XML Java xsd
I need to develop a validator for a large xml agains xsd.I've developed it..But now requirement changed. Now i need partial xml validator..which means it should return true though xml validated partially..

For example





In the above code..even the two products are right validator should return true.

The java validator which i've used

package com.xmlpack;
import javax.xml.XMLConstants;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.validation.*;
import org.xml.sax.SAXException;

public class SampleXmlValidator  {

	public static void main(String args[]) throws SAXException, IOException {

		// Construct a StreamSource from a File.
		Source xmlFile = new StreamSource(new File(
		// SchemaFactory is a schema compiler. It reads external representations
		// of schemas and prepares them for validation.
		SchemaFactory schemaFactory = SchemaFactory

		// This object represents a set of constraints that can be checked/
		// enforced against an XML document.
		Schema schema = schemaFactory.newSchema(new File(

		// A processor that checks an XML document against Schema.
		Validator validator = schema.newValidator();
		try {
			System.out.println(xmlFile.getSystemId() + " is valid");
		} catch (SAXException e) {
			System.out.println(xmlFile.getSystemId() + " is NOT valid");
			System.out.println("Reason: " + e.getLocalizedMessage());
Posted 7-Aug-12 18:50pm
Updated 7-Aug-12 23:40pm
barneyman 8-Aug-12 0:03am
The point about XSDs is that document passes, or doesn't there's no such thing as 'partial' validation - maybe you want to look at introducing child namespaces and other XSDs??

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100