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 Siarhei Biarozkin <sb...@zandar.com> on 2002/09/16 17:47:25 UTC

Fw: XML Schema validation question

----- Original Message -----
From: "Siarhei Biarozkin" <sb...@zandar.com>
To: <xe...@xml-apache-org>
Sent: Monday, September 16, 2002 4:45 PM
Subject: XML Schema validation question


> Hello,
> My question is probably a basic one, but I can't browse the archives as
> they're currently unavailable.
> I'm using Xerces 2.1.0 from Tomcat  4.1.10 on Windows XP, I've put the
jars
> in %CATALINA_HOME%common/endorced.
> I'd like to validate the following instance:
> <!-- /WEB-INF/devices/fusion/config/devices.xml -->
> <dev:Devices xmlns:dev="http://zandar.com/devices"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>      xsi:schemaLocation="http://www.zandar.com/devices devices.xsd">
> <!-- content is not shown -->
> </dev:Devices>
>
> The schema,  /WEB-INF/devices/fusion/config/devices.xsd :
> <xs:schema targetNamespace="http://www.zandar.com/devices"
>                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
>                         xmlns:tns="http://www.zandar.com/devices">
> <xs:element name="Devices">
> <!-- content is not shown -->
> </xs:element>
> </xs:schema>
>
> Here's the code :
>
> String configPath = "/WEB-INF/devices/fusion/config/devices.xml";
> InputSource configStream = new InputSource(new BufferedInputStream(
>
getServletContext().
>
> getResourceAsStream(configPath)));
>
>
configStream.setSystemId("file://D:/Tech/Java/J2EE/tomcat4.1.10/webapps/zand
> ar/WEB-INF/devices/fusion/config/devices.xml");
>
> // I've also tried setting systemId with file:/// (the same as above),
> getResource (configPath).toString()
>
>  SAXParserFactory factory = SAXParserFactory.newInstance();
>  SAXParser parser = factory.newSAXParser();
>   XMLReader reader = parser.getXMLReader();
>             try {
>              reader.setFeature("http://xml.org/sax/features/validation",
> true);
>
> reader.setFeature("http://apache.org/xml/features/validation/schema",
true);
>             } catch (Exception e) {
>                 System.err.println("Cannot activate validation." +
> e.getMessage());
>             }
>
>             ConfigContentHandler handler = new ConfigContentHandler();
>             reader.setContentHandler(handler);
>             reader.setErrorHandler(handler);
>             reader.parse(configStream);
>
> I get an exception from Xerces that it's unable to locate a dev:Devices
> element declaration;
> I think my problem with systemId, as I've validated the above instance
with
> XSV.
>
>
> Thanks
> Sergey Beryozkin
>
>


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


Re: Having problems with errant PCDATA using validating SAXParser

Posted by "Paul A. Mayer" <pm...@ifka.dk>.
<Embarrassed>I'm not aware of the FAQ you refer to, could you please 
point out where I might find it</Embarrassed>

I've implemented a Document Handler that captures tag names, tag ids and 
what lies between, but what I don't understand is why the validator does 
not catch the fact that there is PCDATA between exclusive tags.  As far 
as I understand it the DTD I've specifies says "container THIS" with 
"content types A or B" and nothing else between.

 From my earlier message:
> The DTD defines the tag structure as follows:
> 
> 
> <!ELEMENT    noe_item (item_rubrik | item_first_rubrik)+>
> <!ATTLIST    noe_item
>             id    CDATA    #REQUIRED
>             >
> 
> <!ELEMENT    item_rubrik    ANY>
> <!ELEMENT       item_first_rubrik       ANY>
> 
> 
> The errant data can look like this:
> 
> <noe_item id="0">
>     LOTS OF PCDATA HERE
>     <item_rubrik>Some text</item_rubrik>
> </noe_item>

If the DTD said:

<!ELEMENT    noe_item (PCDATA | item_rubrik | item_first_rubrik)+>
                        ^^^^^^

I could understand this validation behaviour, and see the need to 
capture the character data indepentent of the tag events.

Prehaps you will be so kind as to enlighten me about this!

/Paul

Joseph Kesselman wrote:
> This sounds like the standard FAQ item: Remember that SAX may deliver 
> contiguous text as several successive calls to characters(). Does your 
> code allow for that?
> 
> ______________________________________
> Joe Kesselman  / IBM Research
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 


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


Re: Having problems with errant PCDATA using validating SAXParser

Posted by Joseph Kesselman <ke...@us.ibm.com>.
This sounds like the standard FAQ item: Remember that SAX may deliver 
contiguous text as several successive calls to characters(). Does your 
code allow for that?

______________________________________
Joe Kesselman  / IBM Research

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


Having problems with errant PCDATA using validating SAXParser

Posted by "Paul A. Mayer" <pm...@ifka.dk>.
Hi,

I have a problem with PCDATA "leaking" between xml tags when using an
instance of the xerces validating SAXParser.  Here's the setup and
thanks in advance for any help!

/Paul


The DTD defines the tag structure as follows:


<!ELEMENT	noe_item (item_rubrik | item_first_rubrik)+>
<!ATTLIST	noe_item
			id	CDATA	#REQUIRED
			>

<!ELEMENT	item_rubrik	ANY>
<!ELEMENT       item_first_rubrik       ANY>


The errant data can look like this:

<noe_item id="0">
	LOTS OF PCDATA HERE
	<item_rubrik>Some text</item_rubrik>
</noe_item>




* The problem is that the validating parser does not throw an error
about the "LOTS OF PCDATA HERE" according to the DTD.  How do I get it
to do that?

I'm using the this parser pattern (a little psuedo code here):

import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

void _parse(InputStream input, DefaultHandler handler){
		factory = SAXParserFactory.newInstance();
		factory.setValidating(true);
		try
		{
			SAXParser saxParser = factory.newSAXParser();
			saxParser.parse(input, handler);
		}
		catch (SAXParseException spe)
		{
			spe.printStackTrace();
		}
		catch (SAXException sxe)
			sxe.printStackTrace();
		}
		catch (ParserConfigurationException pce)
		{
			pce.printStackTrace();
		}
		catch (IOException ioe)
		{
			ioe.printStackTrace();
		}
}



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


Re: XML Schema validation question

Posted by Siarhei Biarozkin <sb...@zandar.com>.
Hi, apologies for the ">" tags, I originally sent it to the wrong address
Thanks

----- Original Message -----
From: "Siarhei Biarozkin" <sb...@zandar.com>
To: <xe...@xml.apache.org>
Sent: Monday, September 16, 2002 4:47 PM
Subject: Fw: XML Schema validation question


>
> ----- Original Message -----
> From: "Siarhei Biarozkin" <sb...@zandar.com>
> To: <xe...@xml-apache-org>
> Sent: Monday, September 16, 2002 4:45 PM
> Subject: XML Schema validation question
>
>
> > Hello,
> > My question is probably a basic one, but I can't browse the archives as
> > they're currently unavailable.
> > I'm using Xerces 2.1.0 from Tomcat  4.1.10 on Windows XP, I've put the
> jars
> > in %CATALINA_HOME%common/endorced.
> > I'd like to validate the following instance:
> > <!-- /WEB-INF/devices/fusion/config/devices.xml -->
> > <dev:Devices xmlns:dev="http://zandar.com/devices"
> >   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >      xsi:schemaLocation="http://www.zandar.com/devices devices.xsd">
> > <!-- content is not shown -->
> > </dev:Devices>
> >
> > The schema,  /WEB-INF/devices/fusion/config/devices.xsd :
> > <xs:schema targetNamespace="http://www.zandar.com/devices"
> >                         xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >                         xmlns:tns="http://www.zandar.com/devices">
> > <xs:element name="Devices">
> > <!-- content is not shown -->
> > </xs:element>
> > </xs:schema>
> >
> > Here's the code :
> >
> > String configPath = "/WEB-INF/devices/fusion/config/devices.xml";
> > InputSource configStream = new InputSource(new BufferedInputStream(
> >
> getServletContext().
> >
> > getResourceAsStream(configPath)));
> >
> >
>
configStream.setSystemId("file://D:/Tech/Java/J2EE/tomcat4.1.10/webapps/zand
> > ar/WEB-INF/devices/fusion/config/devices.xml");
> >
> > // I've also tried setting systemId with file:/// (the same as above),
> > getResource (configPath).toString()
> >
> >  SAXParserFactory factory = SAXParserFactory.newInstance();
> >  SAXParser parser = factory.newSAXParser();
> >   XMLReader reader = parser.getXMLReader();
> >             try {
> >              reader.setFeature("http://xml.org/sax/features/validation",
> > true);
> >
> > reader.setFeature("http://apache.org/xml/features/validation/schema",
> true);
> >             } catch (Exception e) {
> >                 System.err.println("Cannot activate validation." +
> > e.getMessage());
> >             }
> >
> >             ConfigContentHandler handler = new ConfigContentHandler();
> >             reader.setContentHandler(handler);
> >             reader.setErrorHandler(handler);
> >             reader.parse(configStream);
> >
> > I get an exception from Xerces that it's unable to locate a dev:Devices
> > element declaration;
> > I think my problem with systemId, as I've validated the above instance
> with
> > XSV.
> >
> >
> > Thanks
> > Sergey Beryozkin
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>


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