The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
[SOLVED]Any XML people out there? -- Nothing to see here.
Okay guys. I need to finish this thing up but I've run into a bump and have NO idea what to do about it. Anyway. I am working on making a validator in Java for my XML file and schema file. For the code our professor has given us a sample one that works for his small, insanely easy XML file. I had to tweak it a little bit, but it works fine. Or so I thought. Once I brought my XML file I was given an error:
Parser encountered a Fatal Error!!!!!!
The markup in the document following the root element must be well-formed.
org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
at org.knoesis.Validator.main(Validator.java:74)
Okay... But I thought my XML file was well formed... Here's my XML file:
I even uploaded it to an online validator and it said it was okay. So I'm stumped... Does anyone have any ideas on what I can do to fix this? I'm tired and I want to go to bed. :P
Code for validator:
package org.knoesis;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import com.sun.org.apache.xerces.internal.jaxp.JAXPConstants;
public class Validator {
public static void main(String[] args) {
try {
// Create a factory
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
// set validating features in the factory
//parsers must be namespace aware to validate
fact.setNamespaceAware(true);
fact.setValidating(true);
//since we are a validating against schema we have to explicitly say that
try {
fact.setAttribute(JAXPConstants.JAXP_SCHEMA_LANGUAGE,
JAXPConstants.W3C_XML_SCHEMA);
} catch (IllegalArgumentException x) {
// Happens if the parser does not support JAXP 1.2
throw new RuntimeException("Cannot use validation here!",x);
}
DocumentBuilder builder = fact.newDocumentBuilder();
// using an anonymous inner class to work with the errors
builder.setErrorHandler(new ErrorHandler() {
@Override
public void error(SAXParseException exception)
throws SAXException {
System.out.println("Parser encountered an Error!");
System.out.println(exception.getMessage());
}
@Override
public void fatalError(SAXParseException exception)
throws SAXException {
System.out
.println("Parser encountered a Fatal Error!!!!!!");
System.out.println(exception.getMessage());
}
@Override
public void warning(SAXParseException exception)
throws SAXException {
System.out
.println("Parser encountered an Warning! Can still proceed");
System.out.println(exception.getMessage());
}
});
// parse a valid instance
Document doc = builder.parse(new File(
"resources/source.xml"));
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
By the way, there aren't any spaces in my XML file because I thought that's what the problem was and I've been too lazy to put them back.
Posts
e: Removing it gave me the same error. Damn. I really wish it was just that. :P