You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Darren Hall <dh...@utrs.com> on 2006/06/29 23:27:03 UTC
xsd and org.apache.commons.digester.Digester
Hi everyone,
I'm unable to parse an XML file I've created using the commons Digester when
I use an xsd file vs. a dtd file.
Is anyone aware of any known issues with this?
I'm using commons-digester-1.7. When I try to validate the xml file against
the xsd, I get the following error -
"2006-06-29 14:50:38,714 ERROR org.apache.commons.digester.Digester - Parse
Fatal Error at line 1 column 3: The markup declarations contained or pointed
to by the document type declaration must be well-formed.
org.xml.sax.SAXParseException: The markup declarations contained or pointed
to by the document type declaration must be well-formed."
The xml file seems to validate properly against a dtd. Also, the xsd file is
incomplete, I know, and I was expecting to get an error - just not the one I
got. The error I ended up getting when I tried to parse the xml file leads
me to believe there may be a problem with the Digester working with xsd
files. I just want to verify that this is the case before I continue writing
this xsd. If not, please let me know what I'm doing wrong and I'll keep
going. (The dtd I validated against was complete - btw.)
Thanks,
Darren
Below are snippets of relevant code -
//Java code that creates the digester and calls parse
[.]
String configPath = "/WEB-INF/classes/uwaf-config.xml";
digester = new Digester();
digester.setNamespaceAware(true);
digester.setValidating(this.isValidating());
digester.setUseContextClassLoader(true);
digester.addRuleSet(new ConfigRuleSet());
digester.push(configPath);
InputStream input = null;
URL url = getServletContext().getResource(configPath);
InputSource is = new InputSource(url.toExternalForm());
input = url.openStream();
is.setByteStream(input);
digester.parse(is);
[.]
//uwaf-config.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE uwaf-config PUBLIC
"-//UTRS//DTD Web Application Framework Configuration 1.0//EN"
"http://www.utrs.com/content/xsd/uwaf-config_1_0.xsd">
<uwaf-config>
<view-mappings type="com.utrs.framework.webapp.examples.PageProcessor">
<view path="/home" forward="/home.jsp" >
<set-property property="home" value="HOME" />
</view>
</view-mappings>
</uwaf-config>
//uwaf-config_1_0.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema version="1.1"
targetNamespace="http://www.utrs.com/content/xml/xsd/uwaf/v10/config"
xmlns:waf="http://www.utrs.com/content/xml/xsd/uwaf/v10/config/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<!-- definition of groups -->
<!-- definition of complex type elements -->
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema version="1.1"
targetNamespace="http://www.utrs.com/content/xml/xsd/uwaf/v10/config"
xmlns:waf="http://www.utrs.com/content/xml/xsd/uwaf/v10/config/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<!-- definition of complex type elements -->
<xs:element name="uwaf-config">
<xs:complexType>
<xs:sequence>
<xs:element ref="waf:view-mappings" minOccurs="0" maxOccurs="1"/>
<xs:attribute ref="waf:id"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- definition of simple type elements -->
<xs:element name="view-mappings" type="xs:string"/>
<!-- definition of simple type attributes -->
<xs:attribute name="id" type="xs:ID" use="optional"/>
</xs:schema>
RE: xsd and org.apache.commons.digester.Digester
Posted by Darren Hall <dh...@utrs.com>.
Simon,
Thanks for the response. Is there anywhere you can point me that might have
an example of how to do this. Also, is this a common issue when working with
commons digester and xsd? I'm not seeing a lot of information about it in my
Google searches.
Thanks,
Darren
-----Original Message-----
From: Simon Kitching [mailto:skitching@apache.org]
Sent: Sunday, July 02, 2006 6:24 PM
To: Jakarta Commons Users List
Subject: RE: xsd and org.apache.commons.digester.Digester
Hi Darren,
On Fri, 2006-06-30 at 16:53 -0400, Darren Hall wrote:
> Hello again,
>
> I fixed the earlier problem I was having with parsing my xml doc, but now
> I'm getting another one -
>
> 2006-06-30 16:04:40,469 ERROR org.apache.commons.digester.Digester - Parse
> Error at line 2 column 13: Document is invalid: no grammar found.
> org.xml.sax.SAXParseException: Document is invalid: no grammar found.
>
> I'm using commons-digester 1.7 and an xsd to read from my xml file.
>
> >From the research I've been doing online, it seems this error could be
> related to the fact that I somehow need to configure the digester to let
it
> know I'm validating using XML schema... but I'm not sure.
>
> Can anyone point me in the right direction as far as solving this problem?
Configuring validation of an xml document against a schema is
unfortunately not standardised; it varies by parser implementation. And
it is a little tricky to get right.
I therefore recommend that you create the parser instance in your own
code, configure it however you desire, then pass that parser instance in
to the Digester (see the Digester constructors taking a SAXParser or
XMLReader). This is much more reliable than trying to use
Digester.setSchema and related methods.
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
RE: xsd and org.apache.commons.digester.Digester
Posted by Simon Kitching <sk...@apache.org>.
Hi Darren,
On Fri, 2006-06-30 at 16:53 -0400, Darren Hall wrote:
> Hello again,
>
> I fixed the earlier problem I was having with parsing my xml doc, but now
> I'm getting another one -
>
> 2006-06-30 16:04:40,469 ERROR org.apache.commons.digester.Digester - Parse
> Error at line 2 column 13: Document is invalid: no grammar found.
> org.xml.sax.SAXParseException: Document is invalid: no grammar found.
>
> I'm using commons-digester 1.7 and an xsd to read from my xml file.
>
> >From the research I've been doing online, it seems this error could be
> related to the fact that I somehow need to configure the digester to let it
> know I'm validating using XML schema... but I'm not sure.
>
> Can anyone point me in the right direction as far as solving this problem?
Configuring validation of an xml document against a schema is
unfortunately not standardised; it varies by parser implementation. And
it is a little tricky to get right.
I therefore recommend that you create the parser instance in your own
code, configure it however you desire, then pass that parser instance in
to the Digester (see the Digester constructors taking a SAXParser or
XMLReader). This is much more reliable than trying to use
Digester.setSchema and related methods.
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
RE: xsd and org.apache.commons.digester.Digester
Posted by Darren Hall <dh...@utrs.com>.
Hello again,
I fixed the earlier problem I was having with parsing my xml doc, but now
I'm getting another one -
2006-06-30 16:04:40,469 ERROR org.apache.commons.digester.Digester - Parse
Error at line 2 column 13: Document is invalid: no grammar found.
org.xml.sax.SAXParseException: Document is invalid: no grammar found.
I'm using commons-digester 1.7 and an xsd to read from my xml file.
>>From the research I've been doing online, it seems this error could be
related to the fact that I somehow need to configure the digester to let it
know I'm validating using XML schema... but I'm not sure.
Can anyone point me in the right direction as far as solving this problem?
Thanks,
Darren
<Relevant Code>
//Java code that creates the digester and calls parse
...
String configPath = "/WEB-INF/classes/uwaf-config.xml";
digester = new Digester();
digester.setNamespaceAware(true);
digester.setValidating(this.isValidating());
digester.setUseContextClassLoader(true);
digester.addRuleSet(new ConfigRuleSet());
digester.push(configPath);
InputStream input = null;
URL url = getServletContext().getResource(configPath);
InputSource is = new InputSource(url.toExternalForm());
input = url.openStream();
is.setByteStream(input);
digester.parse(is);
...
//uwaf-config.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<uwaf-config xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation =
"http://www.utrs.com/content/uwaf/v10/xsd/">
<view-mappings type="com.utrs.framework.webapp.examples.PageProcessor">
<view path="/home" forward="/home.jsp" >
<set-property property="home" value="HOME" />
</view>
</view-mappings>
</uwaf-config>
//uwaf-config_1_0.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema version="1.1"
targetNamespace="http://www.utrs.com/content/xml/xsd/uwaf/v10/config"
xmlns:waf="http://www.utrs.com/content/xml/xsd/uwaf/v10/config/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<!-- definition of complex type elements -->
<xs:element name="uwaf-config">
<xs:complexType>
<xs:sequence>
<xs:element name="view-mappings" type="map-list" maxOccurs="1"/>
<xs:attribute name="id" type="id" use="optional"/>
</xs:sequence>
</xs:complexType>
</xs:element>
...
-----Original Message-----
From: Darren Hall [mailto:dhall@utrs.com]
Sent: Thursday, June 29, 2006 5:27 PM
To: commons-user@jakarta.apache.org
Subject: xsd and org.apache.commons.digester.Digester
Hi everyone,
I'm unable to parse an XML file I've created using the commons Digester when
I use an xsd file vs. a dtd file.
Is anyone aware of any known issues with this?
I'm using commons-digester-1.7. When I try to validate the xml file against
the xsd, I get the following error -
"2006-06-29 14:50:38,714 ERROR org.apache.commons.digester.Digester - Parse
Fatal Error at line 1 column 3: The markup declarations contained or pointed
to by the document type declaration must be well-formed.
org.xml.sax.SAXParseException: The markup declarations contained or pointed
to by the document type declaration must be well-formed."
The xml file seems to validate properly against a dtd. Also, the xsd file is
incomplete, I know, and I was expecting to get an error - just not the one I
got. The error I ended up getting when I tried to parse the xml file leads
me to believe there may be a problem with the Digester working with xsd
files. I just want to verify that this is the case before I continue writing
this xsd. If not, please let me know what I'm doing wrong and I'll keep
going. (The dtd I validated against was complete - btw.)
Thanks,
Darren
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org