• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Whitespace required before attributes

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like your XML string contains some weird character instead of the regular whitespace. You might want to catch the SAXParseException and print out "e.getLineNumber()" and "e.getColumnNumber()" to pinpoint the source of the error.
 
Marshall B Thompson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I did as suggested and got:
Whitespace required before attributes.
8611374
-1
The file is way too big to pull into any visual tool. Is there no way to ignore that message? Or is it preventing the parser from reading the input xml?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you need a modified InputStream or Reader class that can examine the characters before they get to the SAX parser and change weird ones to spaces.
I have had a hard time with those accursed MS Word "smart quotes" and have to filter them out.
What do you know about the character set that is supposed to be in the file?
Bill
 
Marshall B Thompson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Turns out, the input xml file was truncated, so this is nothing I could have ignored via parser settings.
File was too big to look at. Perl script to show a specific line number proved that that line was truncated in the middle of an element name.
 
reply
    Bookmark Topic Watch Topic
  • New Topic