Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Create custom schema(tag) doesn't work

  1. #1
    Join Date
    Feb 2010
    Posts
    22

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Post your code... It does work created several custom tags/schema's without problems...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2010
    Posts
    22

    Default

    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>

  4. #4
    Join Date
    Feb 2010
    Posts
    22

    Default

    Any suggestions?

  5. #5
    Join Date
    Feb 2010
    Posts
    22

    Default

    Somebody, please help.

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

  6. #6
    Join Date
    Feb 2010
    Posts
    22

    Default

    I am still need help!!!

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Could you post your project instead of the code (simply attach). At first glance there isn't nothing, obviously, wrong with your code.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8
    Join Date
    Feb 2010
    Posts
    22

    Default

    Here is a maven project

    SpringTestMaven.zip

  9. #9
    Join Date
    Feb 2010
    Posts
    22

    Default

    Any suggestions?

  10. #10
    Join Date
    Feb 2010
    Posts
    22

    Default

    S.O.S.
    I still need help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •