Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Having a really bad time, and I fear it's all line endings

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Andrew Thompson <lordpixel AT mac.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Having a really bad time, and I fear it's all line endings
  • Date: Sun, 6 Mar 2005 12:51:18 -0500

Hi all,

I've been trying to use XOM as an XInclude resolver, so I wrote a little program to take some XHTML document I had and resolve the includes:

public class XIncluder {

/** Creates a new instance of Xincluder */
public XIncluder(File a_inputFile, File a_outputFile) {
try {
System.out.println("Resolving includes in " + a_inputFile + " to " + a_outputFile);
if ( !a_inputFile.exists() ) {
System.err.println(a_inputFile + "does not exist");
} else {
Document unresolved = new Builder().build(a_inputFile);
DocType dt = unresolved.getDocType();
Document resolved = nu.xom.xinclude.XIncluder.resolve(unresolved);
resolved.setDocType(new DocType(dt.getRootElementName(), dt.getPublicID(), dt.getSystemID()));
if ( a_outputFile.exists() ) {
System.err.println(a_outputFile + " already exists.");
} else {
OutputStream destFile = new BufferedOutputStream(new FileOutputStream(a_outputFile));
Serializer s = new Serializer(destFile);
s.write(resolved);
}
}
} catch (Exception E) {
System.err.println(E.getMessage());
E.printStackTrace(System.err);
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] a_args) {
if ( a_args.length != 2 ) {
System.out.println("usage: Xincluder inputfile outputfile");
System.exit(1);
}
File cwd = new File(System.getProperty("user.dir"));
new XIncluder(new File(cwd, a_args[0]), new File(cwd, a_args[1]));
}

}

The first few lines of the file I'm trying to resolve looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";
xmlns:xi="http://www.w3.org/2001/XInclude";
xml:lang="en" lang="en">
<head>
<!--meta data and links-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Content-Style-Type" content="text/css"/>

But no matter what I do, all that I get from this code is this:

Document root element is missing.
nu.xom.ParsingException: Document root element is missing. at line 1, column -1.
at nu.xom.Builder.build(Unknown Source)
at nu.xom.Builder.build(Unknown Source)
at nu.xom.Builder.build(Unknown Source)
at xincluder.XIncluder.<init>(XIncluder.java:39)
at xincluder.XIncluder.main(XIncluder.java:66)

I'm saving this file on OS X with TextWrangler.
I'm telling it to save as UTF-8 with a BOM.
I've tried asking it to save with Unix, DOS and Macintosh line endings, but nothing seems to make a difference.

So I created another smaller file by copying and pasting part of my original file. Eventually, after really stripping it down and re-saving it multiple times I found I could get XOM to deal with the file.

So I fear I've got a file with messed up line endings, but after 2 hours I'm pulling my hair out.
Does this look like it's the problem to anyone else or have I missed something?
Is there a surefire way to cleanup a file that anyone knows?
Can I get XOM to help me normalize line endings?

AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside

(see you later space cowboy ...)





Archive powered by MHonArc 2.6.24.

Top of Page