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 "Md. Samiul Hoque (Commented) (JIRA)" <xe...@xml.apache.org> on 2012/02/25 13:39:48 UTC

[jira] [Commented] (XERCESJ-719) ignorableWhitespace() not being called with XML Schema

    [ https://issues.apache.org/jira/browse/XERCESJ-719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13216414#comment-13216414 ] 

Md. Samiul Hoque commented on XERCESJ-719:
------------------------------------------

ROFLMAO
i created my account here just to say this
                
> ignorableWhitespace() not being called with XML Schema
> ------------------------------------------------------
>
>                 Key: XERCESJ-719
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-719
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: SAX
>    Affects Versions: 2.4.0
>         Environment: Operating System: Windows NT/2K
> Platform: PC
>            Reporter: Jay Rostosky
>
> When schema is DTD, characters() and ignorableWhitespace() called correctly.
> However, when schema is XML Schema, all whitespace reported to characters().
> A testcase has been developed, included below.
> (This is, of course, when defining an element with element content.)
> File: WhitespaceTest.java
> -------------------------
> import javax.xml.parsers.*;
> import org.xml.sax.*;
> import org.xml.sax.helpers.DefaultHandler;
> import java.io.FileReader;
> public class WhitespaceTest
> extends DefaultHandler
> {
>    public void startElement(String nsURI, String localName, String qName, 
> Attributes atts)
>    throws SAXException
>    {
>       System.out.println("<" + qName + ">");
>    }
>    
>    public void endElement(String nsURI, String localName, String qName)
>    throws SAXException
>    {
>       System.out.println("</" + qName + ">");
>    }
>    /* 
>     * From the SAX Javadoc - characters method
>     * Note that some parsers will report whitespace in element content using 
>     * the ignorableWhitespace method rather than this one 
>     * (validating parsers must do so).
>     */
>    public void characters(char[] data, int start, int length)
>    throws SAXException
>    {
>       String content = new String(data, start, length);
>       System.out.println("DATA[" + content + "]");
>    }
>    /*
>     * From the SAX Javadoc - ignorableWhitespace method
>     * Validating Parsers must use this method to report each chunk of 
> whitespace 
>     * in element content (see the W3C XML 1.0 recommendation, section 2.10): 
>     * non-validating parsers may also use this method if they are capable of 
>     * parsing and using content models.
>     */
>    public void ignorableWhitespace(char[] data, int start, int length)
>    throws SAXException
>    {
>       String ws = new String(data, start, length);
>       System.out.println("ws{" + ws + "}");
>    }
>    
>    // ignore fatalError()s and warning()s   
>    public void error(SAXParseException e)
>    {
>       System.out.println("**** Error: " + e.getMessage());
>    }
>    public static void main(String[] args)
>    throws Exception
>    {
>       SAXParserFactory factory = SAXParserFactory.newInstance();
>       factory.setValidating(true);
>       factory.setNamespaceAware(true);
>       SAXParser parser = factory.newSAXParser();
>       parser.setProperty
> ("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
>                          "http://www.w3.org/2001/XMLSchema");
>       DefaultHandler handler = new WhitespaceTest();
>       InputSource source = new InputSource(new FileReader
> ("WhitespaceTest.xml"));
>       
>       parser.parse(source, handler);
>       System.out.println("\nParse completed successfully.");      
>    }
> }
> File: WhitespaceTest.xml
> ------------------------
> <?xml version='1.0'?>
> <!-- To see the bug behavior, comment out the DTD and use the Schema only.
>      All whitespace will be indicated by DATA[] in the handler.
>      Bring the DTD back in and you will see both DATA[] and ws{} being used. -->
> <!--DOCTYPE test
> [
> <!ELEMENT test (question+)>
> <!ATTLIST test xmlns:xsi CDATA #FIXED 'http://www.w3.org/2001/XMLSchema-
> instance'
>                xsi:noNamespaceSchemaLocation CDATA #REQUIRED>
> <!ELEMENT question (#PCDATA)>
> ]-->
> <test xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
>       xsi:noNamespaceSchemaLocation='WhitespaceTest.xsd'>
>   <question>  this is significant whitespace -> characters() </question>
>   <question> whitespace between element tags is not -> ignorableWhitespace()  
> </question>
> </test>
> File: WhitespaceTest.xsd
> ------------------------
> <?xml version='1.0'?>
> <xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
>   <xsd:element name='test'>  <!-- an element with element content -->
>     <xsd:complexType>
>       <xsd:sequence>
>         <xsd:element name='question' type='xsd:string' maxOccurs='unbounded'/>
>       </xsd:sequence>
>     </xsd:complexType>
>   </xsd:element>
> </xsd:schema>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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