package com.jxml.quick.examples.batch;
import com.jxml.quick.*;
import org.xml.sax.*;
import java.io.*;
import java.util.*;
import com.jxml.protocol.*;

public class Main
{
    public static void main(String[] args)
    {
	try
	    {
		Protocol.addJXMLProtocolPackage();
		QDoc schema=Quick.parseSchema("file:batch.qiml");
		
		QDoc testSchema=Quick.parseSchema("file:test.qiml");
		
		QDoc doc=Quick.parse(schema,"file:batch.xml");
		
		ArrayList list=(ArrayList)Quick.getRoot(doc);
		int s=list.size();
		int i;
		for (i=0;i<s;++i)
		    {
			System.out.println();
			Item item=(Item)list.get(i);
			String href=item.href;
			boolean failure=item.expectFailure;
			System.out.println("test="+(i+1)+" href="+href+", expectFailure="+failure);
			boolean success=false;
			try
			    {
				Quick.parse(testSchema,href);
				success=true;
			    }
			catch (SAXParseException tpe)
			    {
				if (!failure)
				    {
					QPE.display(tpe);
					System.exit(0);
				    }
			    }
			catch (Exception te)
			    {
				QPE.display(te);
				System.exit(0);
			    }
			if (success && failure)
			    {
				System.out.println("Error: Unexpected Success");
				System.exit(0);
			    }
		    }
	    } 
	catch (Exception e)
	    {
		QPE.display(e);
	    }
    }
}
