0

I am getting this error:

org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: 'duke duke' is not a valid value for 'NCName'.

I am using this spring-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
bean id="duke duke"
    class="Juggler"/>
/beans>

My bean id's value has spaces in between.

This is my main class:

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class Main {

    public static void main(String[] args)
    {
        ApplicationContext ctx=new ClassPathXmlApplicationContext("config/spring-config.xml");
        Juggler jg=(Juggler)ctx.getBean("duke duke");
        jg.perform();        
    }
}

However if I change the xsd in spring-config to spring-beans-3.1.xsd. I don't get this error. Why is it so??

  • ID has to conform to the XML ID specification and as such cannot contain spaces. See http://stackoverflow.com/questions/1077084/what-characters-are-allowed-in-dom-ids . – M. Deinum Dec 09 '13 at 08:27
  • Right , even I thought so.But somehow the spaces with 3.1.xsd works and I want to know how this is possible... – user3079368 Dec 10 '13 at 07:00
  • The datatype changed. < 3.1 it was `xsd:ID` >= 3.1 it is `xsd:string`. (Just take a look at the xsd). – M. Deinum Dec 10 '13 at 07:05
  • Thanks you are right ..checked the xsd's for both versions.So it concludes that 3.1 xsd allows you strings in id which in turn allows spaces and other special characters. – user3079368 Dec 10 '13 at 08:30

0 Answers0