You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Jon Brisbin <jo...@npcinternational.com> on 2004/07/23 23:18:23 UTC

Errors loading XML file with validation

I've searched on the ML archives and can't find what I'm looking, but I
might just be stupid and can't find it.

I'm using Jelly to load this file, but that list directed me here.  here's
what I'm getting:

328  [main] ERROR org.apache.commons.jelly.parser.XMLParser  - Parse Error
at line 2 column 247: cvc-elt.1: Cannot find the declaration of element
'x:action'.
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of
element 'x:action'.
	at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
	at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown
Source)
	at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown
Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
Source)
	at
org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRoot
ElementHook(Unknown Source)
	at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc
her.dispatch(Unknown Source)
	at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:328)
	at com.npci.xportal.Test.main(Test.java:54)

This XML file validates in XMLSpy just fine.  Here's the root element
declarations I'm using:


<x:action
	xmlns="http://npci.com/xportal/1.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:x="http://npci.com/xportal/1.0"
	xsi:schemaLocation="-//http://npci.com/xportal/1.0//-
D:\projects\xportal-definitions\xsd\jdbc-handler.xsd">

Here's the code I'm using to parse with:

			StringWriter sw = new StringWriter();
			XMLSerializer ser = new XMLSerializer(sw, (new OutputFormat()));
			SAXParser parser = new SAXParser();
			parser.setFeature(
					"http://apache.org/xml/features/validation/schema", true);
			parser.setFeature(
					"http://xml.org/sax/features/validation", true);
			parser.setFeature(
					"http://xml.org/sax/features/namespaces", true);
			parser.setFeature(
					"http://xml.org/sax/features/namespace-prefixes", false);

			XMLParser jellyParser = new XMLParser(parser);
			XMLOutput jellyOutput = new XMLOutput(ser.asContentHandler());
			Script jellyScript = jellyParser

.parse("d:/projects/xportal-definitions/actions/sql/payroll/get_check_hdr.xm
l");
			jellyScript.compile();
			jellyScript.run((new JellyContext()), jellyOutput);

			System.out.println("[After]: " + sw.toString());

			ByteArrayInputStream bais = new ByteArrayInputStream(sw.toString()
					.getBytes());
			DefaultConfigurationBuilder configBuilder = new
DefaultConfigurationBuilder();
			Configuration config = configBuilder.build(bais);

			System.out.println("[Config]: "
					+ ConfigurationUtil.toString(config));

If I change the feature "http://xml.org/sax/features/namespace-prefixes" to
"false", then I get an error because the XML is corrupted to this:

<x:action
	schemaLocation="-//http://npci.com/xportal/handler/JDBC/1.0//-
file:///D:/projects/xportal-definitions/xsd/jdbc-handler.xsd"
="http://npci.com/xportal/handler/JDBC/1.0"
	xmlns="http://npci.com/xportal/handler/JDBC/1.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Any help you could give me here would be MUCH appreciated...


Thanks!

Jon Brisbin
=======================================
Development Programmer
NPC International
(620) 235-7726



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Content is not allowed in prolog error when sax parsing large file

Posted by Duane Jung <du...@yahoo.com>.
Hi Simon,

That was the exact problem!  I had some invisible characters from my dataset creation process. 
Thank you very much!!!

Duane

--- Simon Kitching <si...@ecnetwork.co.nz> wrote:
> On Sat, 2004-07-24 at 11:06, Duane Jung wrote:
> > Hi,
> > 
> > While parsing a large XML file (1000 items/56mb), I get the following error:
> > 
> > [Fatal Error] 1k_CIN.xml:2:1: Content is not allowed in prolog.
> > 
> > I've chopped this file up into smaller sets of items (50 items/1.5mb) and can parse those
> without
> > any problems.  Its only when I try to parse the larger file that I encounter the prolog error.
> > 
> > The prolog is the same in all of the files:
> > <?xml version="1.0" encoding="UTF-8"?>
> > 
> > I'm using xerces-2_6_2, parsing with Sax XMLReader.  I've tried passing in a system id and
> > inputsource to the parser -- both result in the prolog error with the larger file.  The
> smaller
> > files parse without any problems.
> > 
> > Does anyone have any ideas?
> 
> Normally, this error message indicates that there is some non-xml
> present before the xml starts.
> 
> I'm wondering if there are some "invisible" chars in your document and
> the way you "chop up" the file is cleaning them out.
> 
> If you are using unix/linux, have you tried inspecting the file using
> something like
>   od -cx input.xml | more
> to see *exactly* what chars your file starts with?
> 
> Regards,
> 
> Simon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 
> 



		
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Content is not allowed in prolog error when sax parsing large file

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Sat, 2004-07-24 at 11:06, Duane Jung wrote:
> Hi,
> 
> While parsing a large XML file (1000 items/56mb), I get the following error:
> 
> [Fatal Error] 1k_CIN.xml:2:1: Content is not allowed in prolog.
> 
> I've chopped this file up into smaller sets of items (50 items/1.5mb) and can parse those without
> any problems.  Its only when I try to parse the larger file that I encounter the prolog error.
> 
> The prolog is the same in all of the files:
> <?xml version="1.0" encoding="UTF-8"?>
> 
> I'm using xerces-2_6_2, parsing with Sax XMLReader.  I've tried passing in a system id and
> inputsource to the parser -- both result in the prolog error with the larger file.  The smaller
> files parse without any problems.
> 
> Does anyone have any ideas?

Normally, this error message indicates that there is some non-xml
present before the xml starts.

I'm wondering if there are some "invisible" chars in your document and
the way you "chop up" the file is cleaning them out.

If you are using unix/linux, have you tried inspecting the file using
something like
  od -cx input.xml | more
to see *exactly* what chars your file starts with?

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Content is not allowed in prolog error when sax parsing large file

Posted by Duane Jung <du...@yahoo.com>.
Hi,

While parsing a large XML file (1000 items/56mb), I get the following error:

[Fatal Error] 1k_CIN.xml:2:1: Content is not allowed in prolog.

I've chopped this file up into smaller sets of items (50 items/1.5mb) and can parse those without
any problems.  Its only when I try to parse the larger file that I encounter the prolog error.

The prolog is the same in all of the files:
<?xml version="1.0" encoding="UTF-8"?>

I'm using xerces-2_6_2, parsing with Sax XMLReader.  I've tried passing in a system id and
inputsource to the parser -- both result in the prolog error with the larger file.  The smaller
files parse without any problems.

Does anyone have any ideas?

Thanks in advance, 
Duane





		
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Errors loading XML file with validation

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hello Jon,

If the target namespace of your schema is 
"http://npci.com/xportal/handler/JDBC/1.0" then you should specify that in 
the schemaLocation instead of 
"-//http://npci.com/xportal/handler/JDBC/1.0//-". Hope that helps.

"Jon Brisbin" <jo...@npcinternational.com> wrote on 07/23/2004 
05:18:23 PM:

> I've searched on the ML archives and can't find what I'm looking, but I
> might just be stupid and can't find it.
> 
> I'm using Jelly to load this file, but that list directed me here. 
here's
> what I'm getting:
> 
> 328  [main] ERROR org.apache.commons.jelly.parser.XMLParser  - Parse 
Error
> at line 2 column 247: cvc-elt.1: Cannot find the declaration of element
> 'x:action'.
> org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of
> element 'x:action'.
>    at
> 
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
> Source)
>    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
>    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
Source)
>    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown 
Source)
>    at 
org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown
> Source)
>    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown
> Source)
>    at 
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
> Source)
>    at
> 
org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRoot
> ElementHook(Unknown Source)
>    at
> 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc
> her.dispatch(Unknown Source)
>    at
> 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> Source)
>    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>    at 
org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:328)
>    at com.npci.xportal.Test.main(Test.java:54)
> 
> This XML file validates in XMLSpy just fine.  Here's the root element
> declarations I'm using:
> 
> 
> <x:action
>    xmlns="http://npci.com/xportal/1.0"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:x="http://npci.com/xportal/1.0"
>    xsi:schemaLocation="-//http://npci.com/xportal/1.0//-
> D:\projects\xportal-definitions\xsd\jdbc-handler.xsd">
> 
> Here's the code I'm using to parse with:
> 
>          StringWriter sw = new StringWriter();
>          XMLSerializer ser = new XMLSerializer(sw, (new 
OutputFormat()));
>          SAXParser parser = new SAXParser();
>          parser.setFeature(
>                "http://apache.org/xml/features/validation/schema", 
true);
>          parser.setFeature(
>                "http://xml.org/sax/features/validation", true);
>          parser.setFeature(
>                "http://xml.org/sax/features/namespaces", true);
>          parser.setFeature(
>                "http://xml.org/sax/features/namespace-prefixes", false);
> 
>          XMLParser jellyParser = new XMLParser(parser);
>          XMLOutput jellyOutput = new XMLOutput(ser.asContentHandler());
>          Script jellyScript = jellyParser
> 
> 
.parse("d:/projects/xportal-definitions/actions/sql/payroll/get_check_hdr.xm
> l");
>          jellyScript.compile();
>          jellyScript.run((new JellyContext()), jellyOutput);
> 
>          System.out.println("[After]: " + sw.toString());
> 
>          ByteArrayInputStream bais = new 
ByteArrayInputStream(sw.toString()
>                .getBytes());
>          DefaultConfigurationBuilder configBuilder = new
> DefaultConfigurationBuilder();
>          Configuration config = configBuilder.build(bais);
> 
>          System.out.println("[Config]: "
>                + ConfigurationUtil.toString(config));
> 
> If I change the feature "http://xml.org/sax/features/namespace-prefixes" 
to
> "false", then I get an error because the XML is corrupted to this:
> 
> <x:action
>    schemaLocation="-//http://npci.com/xportal/handler/JDBC/1.0//-
> file:///D:/projects/xportal-definitions/xsd/jdbc-handler.xsd"
> ="http://npci.com/xportal/handler/JDBC/1.0"
>    xmlns="http://npci.com/xportal/handler/JDBC/1.0"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> 
> Any help you could give me here would be MUCH appreciated...
> 
> 
> Thanks!
> 
> Jon Brisbin
> =======================================
> Development Programmer
> NPC International
> (620) 235-7726
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org