Tuesday, December 21, 2010

SAXParseException: White spaces are required between publicId and systemId

An error often encountered by newbies building webapps using Spring3 ..

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from ServletContext resource [/WEB-INF/myservlet-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.

This occurs due to improper sequence of entries in schemaLocation definition in spring configuration (say /WEB-INF/myservlet-servlet.xml).

sample of incorrect entries
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/context
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

This will cause,
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from ServletContext resource [/WEB-INF/myservlet-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.


Correct the order of entries so that Namespace and Schemalocation are defined alternately within the schemaLocation attribute.

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

DTD:
Defines xml document structure .
Saved as .dtd file and can be referenced in an xml document.

Here is a good tutorial on dtd.

Schema definition:
Successor to dtd.
Superior.
Is written as xml and saved in .xsd file.

More on schema can be found here.

2 comments: