Re: Taglib Import: xml Validation Errors with

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Friday, December 7, 2007, 11:37:29 AM, Attila Szegedi wrote:

> Sure, try turning validation off and see whether it fixes your  
> problem. It is really easy to rebuild freemarker.jar, you just need to
> issue "ant jar" -- build.xml will download all required dependencies  
> from the Internet automatically.
>
> It is indeed a curious problem that you're getting these errors. I  
> guess the JAXP "setValidation(true)" would mandate DTD validation, and
> it doesn't consider XML Schema validation? Just a guess...

One can only guess... the XML API of Java with all of its little
intricacies, lack of proper documentation, together with the big
choice of bogus implementations that you can freely chose from, BUT
you don't know which one will the clients use, could be a prime
example of why Java/other-industry-standards suck. Whatever... my
question is:

   factory.setNamespaceAware(false)

Why?

(BTW, did you know that SAXParserFactory.newInstance() can be quite
expensive? At least some say that. Yeah, many say it should be pooled,
especially as it can include expensive lookups on some configs. And
some say, even the result of newSAXParser() should be pooled, if you
read many XML-s. Well, OK, I can implement everything... but it will
be funny if all little component that often parsers XML files maintain
its own pool... I can't believe it's not done by the newSomething()
calls. Frankly, till now I have already pooled/cached
SAXParserFactory-es, due to paranoia. I will soon test if it does
mater for SAXParser-s too... I don't want to believe that.)

> Attila.
>
> On 2007.12.07., at 11:04, Michael Wohlfart wrote:
>
>> Hi there,
>>
>> I just started using FreeMarker to replace some of my JSP-Views
>> in my Spring Application and I am pretty impressed so far.
>>
>> The only ugly thing I could find is an validation error when
>> using Taglibs. My Environment ist Spring 2.5, Tomcat 6.0.14,
>> FreeMarker 2.3.11. JRE6
>>
>> My Import of the taglib in my Template looks like this:
>> <#assign c=JspTaglibs["http://java.sun.com/jstl/core_rt"] />
>>
>> I guess it is not the standard way, most examples I found
>> use the "*.tld" path here, but this seems to work.
>>
>> At view creation time I get the following validation Errors:
>>
>> Warning: validation was turned on but an org.xml.sax.ErrorHandler  
>> was not
>> set, which is probably not what is desired.  Parser will use a default
>> ErrorHandler to print the first 10 errors.  Please call
>> the 'setErrorHandler' method to fix this.
>> Error: URI=jndi:/localhost/cms/WEB-INF/web.xml Line=6: Document root  
>> element "web-app", must match DOCTYPE root "null".
>> Error: URI=jndi:/localhost/cms/WEB-INF/web.xml Line=6: Document is  
>> invalid: no grammar found.
>> Warning: validation was turned on but an org.xml.sax.ErrorHandler  
>> was not
>> set, which is probably not what is desired.  Parser will use a default
>> ErrorHandler to print the first 10 errors.  Please call
>> the 'setErrorHandler' method to fix this.
>> Error: URI=jar:file:/E:/cfs_web/.metadata/.plugins/ 
>> org.eclipse.wst.server.core/tmp1/wtpwebapps/cms/WEB-INF/lib/ 
>> standard.jar!META-INF/c.tld Line=6: Document root element "taglib",  
>> must match DOCTYPE root "null".
>> Error: URI=jar:file:/E:/cfs_web/.metadata/.plugins/ 
>> org.eclipse.wst.server.core/tmp1/wtpwebapps/cms/WEB-INF/lib/ 
>> standard.jar!META-INF/c.tld Line=6: Document is invalid: no grammar  
>> found.
>> Warning: validation was turned on but an org.xml.sax.ErrorHandler  
>> was not
>> set, which is probably not what is desired.  Parser will use a default
>> ErrorHandler to print the first 10 errors.  Please call
>> the 'setErrorHandler' method to fix this.
>> [...]
>>
>>
>> my web.xml starts like this and I am not sure what the validation
>> whining is about:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <web-app id="blabla-System"
>>         version="2.4"
>>         xmlns="http://java.sun.com/xml/ns/j2ee"
>>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd 
>> ">
>>
>>    <display-name>blabla System</display-name>
>> [...]
>>
>>
>> So based on the opinion that i am smarter than the xml-validator,  
>> and that the
>> tlds in the jar file are correct I want to turn off xml-validation  
>> (somewhat
>> risky i know). Is there a way to use my own TaglibFactory, the  
>> default implementation
>> turns on the validation somewhere around line 370 as far as i  
>> understand the code,
>> setting the validation to off in this method should do the job ?
>>
>>    private static void parseXml(InputStream in, String url,  
>> DefaultHandler handler)
>>    throws
>>        ParserConfigurationException, IOException, SAXException
>>    {
>>        InputSource is = new InputSource();
>>        is.setByteStream(in);
>>        is.setSystemId(url);
>>        SAXParserFactory factory = SAXParserFactory.newInstance();
>>        factory.setNamespaceAware(false);
>>        factory.setValidating(true);
>>        XMLReader reader = factory.newSAXParser().getXMLReader();
>>        reader.setEntityResolver(new LocalTaglibDtds());
>>        reader.setContentHandler(handler);
>>        reader.parse(is);
>>    }
>>
>>
>> I am open for any other suggestions to get rid of the ugly  
>> validation errors.
>>
>>
>> thanks & best regards
>> Michael
>
>
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user

-- 
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.