You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Brendon Towle <bt...@knowledgeplanet.com> on 2001/03/08 20:09:48 UTC

Ignoring whitespace with schema validation

I'm having problems getting Xerces-j 1.3.0 to really ignore 
whitespace.  I'm getting the same problem with complicated docs and 
schemas, but I'm able to reproduce it with a very simple doc and 
schema.

Here's my test XML doc:

<?xml version="1.0"?>
<test xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="data/test.xsd">

</test>



Here's my schema:

<schema xmlns="http://www.w3.org/2000/08/XMLSchema">
   <element name="test" type="TestType"/>

   <complexType name="TestType">
   </complexType>

</schema>



And here's the code where I initialize the parser:

    private DOMParser getNewParser() {
       DOMParser parser = new DOMParser();
       try {
          parser.setIncludeIgnorableWhitespace(false);
          parser.setFeature("http://xml.org/sax/features/validation", true);
          parser.setFeature(
            "http://apache.org/xml/features/validation/schema",
            true);
          parser.setFeature(
            "http://apache.org/xml/features/dom/include-ignorable-whitespace",
            false);
       } catch (Exception e) {
          // ???
          e.printStackTrace();
       }
       return parser;
    }


(I've tried it with and without the "validation/schema" feature, and 
it fails in the same way.)


Yet, even with all that, I still get a whitespace #text node under 
the <text> node in my document, and isIgnorableWhitespace() returns 
false on that node.  But, I know that the parser is finding the 
schema (because if I put a syntax error in the schema, it barfs). 
Although, interestingly enough, the parse succeeds even when it barfs 
on the schema, and I get the same result.

I'm sure this is some obvious newbie error, but I'm stumped.  Any help?

B.
-- 
Brendon Towle
KnowledgePlanet
Competitive Advantage Through People
Research and Development
5900 Hollis Street, Suite A
Emeryville, CA  94608
p: 510-768-2433
f:  510-768-2444
e: btowle@knowledgeplanet.com

Visit Us:  http://www.knowledgeplanet.com/

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


Re: Ignoring whitespace with schema validation

Posted by Brendon Towle <bt...@knowledgeplanet.com>.
>On Thu, 8 Mar 2001, Brendon Towle wrote:
>
>>      private DOMParser getNewParser() {
>>         DOMParser parser = new DOMParser();
>>         try {
>>            parser.setIncludeIgnorableWhitespace(false);
>>            parser.setFeature("http://xml.org/sax/features/validation", true);
>>            parser.setFeature(
>>              "http://apache.org/xml/features/validation/schema",
>>              true);
>>            parser.setFeature(
>> 
>>"http://apache.org/xml/features/dom/include-ignorable-whitespace",
>>              false);
>>         } catch (Exception e) {
>>            // ???
>>            e.printStackTrace();
>>         }
>>         return parser;
>>      }
>>
>>
>>  (I've tried it with and without the "validation/schema" feature, and
>>  it fails in the same way.)
>
>I believe you also need the namespaces feature turned on to make schema
>validation work.

Unfortunately, turning on namespaces doesn't help the problem either. 
Thanks, though; I'm assuming it's exactly that kind of newbie error.

B.
-- 
Brendon Towle
KnowledgePlanet
Competitive Advantage Through People
Research and Development
5900 Hollis Street, Suite A
Emeryville, CA  94608
p: 510-768-2433
f:  510-768-2444
e: btowle@knowledgeplanet.com

Visit Us:  http://www.knowledgeplanet.com/

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


Re: Ignoring whitespace with schema validation

Posted by Ian Roberts <ir...@decisionsoft.com>.
On Thu, 8 Mar 2001, Brendon Towle wrote:

>     private DOMParser getNewParser() {
>        DOMParser parser = new DOMParser();
>        try {
>           parser.setIncludeIgnorableWhitespace(false);
>           parser.setFeature("http://xml.org/sax/features/validation", true);
>           parser.setFeature(
>             "http://apache.org/xml/features/validation/schema",
>             true);
>           parser.setFeature(
>             "http://apache.org/xml/features/dom/include-ignorable-whitespace",
>             false);
>        } catch (Exception e) {
>           // ???
>           e.printStackTrace();
>        }
>        return parser;
>     }
> 
> 
> (I've tried it with and without the "validation/schema" feature, and 
> it fails in the same way.)

I believe you also need the namespaces feature turned on to make schema
validation work.

Ian

-- 
Ian Roberts, Software Engineer        DecisionSoft Ltd.
tel: +44-1865-203192                  http://www.decisionsoft.com


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