Announcement Announcement Module
Collapse
No announcement yet.
Create custom schema(tag) doesn't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create custom schema(tag) doesn't work

    Hi
    I am trying to create custom tag and using this tutorial http://static.springsource.org/sprin...sible-xml.html - but it doesn't work.

    I receive org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.

    Why example from official tutorial doesn't work?

    How to fix this problem?

  • #2
    Post your code... It does work created several custom tags/schema's without problems...

    Comment


    • #3
      Here is my code

      spring.handlers
      http\://www.mycompany.com/schema/myns=org.springframework.samples.xml.MyNamespaceHa ndler
      spring.schemas
      http\://www.mycompany.com/schema/myns/myns.xsd=org/springframework/samples/xml/myns.xsd
      /org/springframework/samples/xml/myns.xsd
      <?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema xmlns="http://www.mycompany.com/schema/myns"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:beans="http://www.springframework.org/schema/beans"
      targetNamespace="http://www.mycompany.com/schema/myns"
      elementFormDefault="qualified"
      attributeFormDefault="unqualified">

      <xsd:import namespace="http://www.springframework.org/schema/beans"/>

      <xsd:element name="dateformat">
      <xsd:complexType>
      <xsd:complexContent>
      <xsd:extension base="beans:identifiedType">
      <xsd:attribute name="lenient" type="xsd:boolean"/>
      <xsd:attribute name="pattern" type="xsd:string" use="required"/>
      </xsd:extension>
      </xsd:complexContent>
      </xsd:complexType>
      </xsd:element>

      </xsd:schema>

      MyNamespaceHandler.java
      package org.springframework.samples.xml;

      import org.springframework.beans.factory.xml.NamespaceHan dlerSupport;

      public class MyNamespaceHandler extends NamespaceHandlerSupport {

      public void init() {
      registerBeanDefinitionParser("dateformat", new SimpleDateFormatBeanDefinitionParser());
      }
      }
      SimpleDateFormatBeanDefinitionParser.java
      package org.springframework.samples.xml;

      import org.springframework.beans.factory.support.BeanDefi nitionBuilder;
      import org.springframework.beans.factory.xml.AbstractSing leBeanDefinitionParser;
      import org.springframework.util.StringUtils;
      import org.w3c.dom.Element;

      import java.text.SimpleDateFormat;

      public class SimpleDateFormatBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

      protected Class getBeanClass(Element element) {
      return SimpleDateFormat.class;
      }

      protected void doParse(Element element, BeanDefinitionBuilder bean) {
      // this will never be null since the schema explicitly requires that a value be supplied
      String pattern = element.getAttribute("pattern");
      bean.addConstructorArg(pattern);

      // this however is an optional property
      String lenient = element.getAttribute("lenient");
      if (StringUtils.hasText(lenient)) {
      bean.addPropertyValue("lenient", Boolean.valueOf(lenient));
      }
      }
      }
      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"
      xmlns:myns="http://www.mycompany.com/schema/myns"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
      http://www.mycompany.com/schema/myns http://www.mycompany.com/schema/myns/myns.xsd">




      <!-- as a top-level bean -->
      <myns:dateformat id="defaultDateFormat" pattern="yyyy-MM-dd HH:mm" lenient="true"/>

      <bean id="jobDetailTemplate" abstract="true">
      <property name="dateFormat">
      <!-- as an inner bean -->
      <myns:dateformat pattern="HH:mm MM-dd-yyyy"/>
      </property>
      </bean>

      </beans>

      Comment


      • #4
        Any suggestions?

        Comment


        • #5
          Somebody, please help.

          It is not normal that sample from Spring ref doesn't work

          Comment


          • #6
            I am still need help!!!

            Comment


            • #7
              Could you post your project instead of the code (simply attach). At first glance there isn't nothing, obviously, wrong with your code.

              Comment


              • #8
                Here is a maven project

                Attachment
                Attached Files

                Comment


                • #9
                  Any suggestions?

                  Comment


                  • #10
                    S.O.S.
                    I still need help

                    Comment


                    • #11
                      Spring Masters!!!

                      Please look at my problem!

                      Comment


                      • #12
                        Move the files to the correct directory (I suggest a maven tutorial)... Your xsd and schema files must be in the resources not in the java directory... Moving them (basically honouring the maven packaging) makes it work...

                        Comment

                        Working...
                        X