Thursday, November 15, 2012

Cannot resolve the name '...' to a(n) 'type definition' component


Suppose you are validating the a xml file against a XML Schema (a .xsd file), and an exception message returns like this:


org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'createNewAdRequest' to a(n) 'type definition' component.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)

Check the if the type declaration is accessible, in order words, has the same scope.


For instance, here is the test.xml file:

<ClassifiedList>
    <ClassifiedAd>
        <id>1234</id>
        <content>
            Vintage 1963 T-Bird.  Less than 300 miles.
            Driven by my daughter until I took it away.
            Serious inquires only. 555-3264 after 7 PM.
        </content>
        <endDate>4/15/2007</endDate>
        <startDate>4/1/2007</startDate>
        <createNewAdRequest>
            <content>YYY</content>
            <endDate>YYY</endDate>
        </createNewAdRequest>
    </ClassifiedAd>  
</ClassifiedList>


And here the respctive XML Schema file - test.xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element type="ClassifiedList" name="ClassifiedList" />
    <xs:complexType name="ClassifiedList">
      <xs:sequence>
        <xs:element minOccurs="0" type="ClassifiedAd"
                        name="ClassifiedAd" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>

    <xs:element type="ClassifiedAd" name="ClassifiedAd" />
    <xs:complexType name="ClassifiedAd">
      <xs:sequence>
        <xs:element type="xs:int" name="id" />
        <xs:element type="xs:string" name="content" />
        <xs:element type="xs:string" name="endDate" />
        <xs:element type="xs:string" name="startDate" />
        <xs:element type="createNewAdRequest" name="createNewAdRequest" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
       
    <xs:element name="createNewAdRequest">
        <xs:complexType name="createNewAdRequest">
            <xs:sequence>
                <xs:element type="xs:string" name="content" />
                <xs:element type="xs:string" name="endDate" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
   
</xs:schema>


The text highlighted in blue defines a new type under its element scope.
So, it is not accessible from outside.
Switch the blue text by the orange below, where the complex type is defined in the same scope of  <ClassifiedList> element.
       
        <xs:complexType name="createNewAdRequest">
            <xs:sequence>
                <xs:element type="xs:string" name="content" />
                <xs:element type="xs:string" name="endDate" />
            </xs:sequence>
        </xs:complexType>
   

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...