I'm sax parsing (via JDK 1.4) a large (too large to view) xml file and am getting a system output message of "Whitespace required before attributes". It had partially processed the file. I had guessed that if I told my parser not to validate, I might get past this issue, but that did not work. I've coded a filter that is basically copying the input xml file minus a few elements.
Is there a way to ignore the whitespace check.
Here's my code (sax.XMLFilter is mine and is not shown):
package sax;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import java.lang.Exception;
import java.io.File;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import sax.XMLFilter;
public class controller
{
public controller()
{
}
public static void main(
String[] args)
{
controller ctl = new controller();
if (args.length != 2)
{
System.out.println(
"Usage:
java controller inputFileName outputFileName");
System.out.println(
"File names may be with paths, or without (current directory).");
System.exit(0);
}
//Get the name of the file or directory to compress.
String strInputFileName = args[0];
String strOutputFileName = args[1];
ctl.doit(strInputFileName, strOutputFileName);
}
private void doit(String pstrInputFileName, String pstrOutputFileName)
{
try
{
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
try {
reader.setFeature("http://xml.org/sax/features/validation",
false);
}
catch (SAXException e) {
System.out.println("could not set parser feature");
}
XMLFilter filter = new XMLFilter(pstrOutputFileName);
reader.setContentHandler(filter);
reader.parse(new InputSource(pstrInputFileName));
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
} //doit
} //class controller