GoogleSearchBox

Custom Search

Friday, June 28, 2013

is invalid; nested exception is org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".

If you are getting extra special characters (like ascii or hexa or any weird characters) in your script/xml/txt file OR
If you are getting an error like below in your logs:


2013-06-28 08:57:02,295 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 67 in XML document from ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)

        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)

        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)

        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)

        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)

        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)

        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)

        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody0(SafeContextLoaderListener.java:75)

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody1$advice(SafeContextLoaderListener.java:57)

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized(SafeContextLoaderListener.java:1)

        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)

        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)

        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)

        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)

        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)

        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)

        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)

        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)

        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)

        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)

        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)

        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

        at org.apache.catalina.core.StandardService.start(StandardService.java:525)

        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Caused by: org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".



The reason could be that your xml file contains some invisible characters to your eye (basically some ansi characters), Normally this happens when you copy the code from internet browser or pdf  and paste into your editor/IDE.

Though you keep formatting the xml, but still the error remains same as shown below:












Solutions #1:
1. Copy the code showing error into just plain notepad.
2. try deleting all the spaces between words and then manually use spacebar to add spaces between words/attributes.
3. Again copy the code from notepad and then paste into your IDE/Editor.

This should have solved.

But, in some cases, this also does not solve the issue.

Solutions #2:
1. Open the same excel file in an advanced editor like notepad++,
2. Go to the "Encode" menu --> choose "Encode in ANSI"
















3. Now you should be able to see all those invisible ansi characters you have derived  while copy pasting  from internet (shown below):













4. So you got now proof that you have some to give company there in your xml file.
    Delete all those, characters manually or by using the editors find/replace (ctrl + h ) option:

















5. Now try changing the encoding to the other formats, you will be surprised to see more invisible characters suddenly becomes visible to you :)















6. Play around with encodings, delete those chars and Save.
    Rerun the application. You should be fine.

If you are in Unix Environment, and you doubt your script file (.sh) contains any special characters, you can view those special characters using VI editor.

Open the file using VI editor:
$ vi <file_name>
Hit Esc
Then type in the command line of the vi editor as (To be able to see the extra characters)-  :set list 
To again hide the special characters or make the file to be seen as normal, type in the command line-  :set nolist