[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4335
  • Last Modified:

src-resolve:Cannot resolve the name 'a:abstractClass' to a(n) 'type definition' component.

Hello experts,
 
   This is actually a follow up question of:
 http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21851472.html

  I am trying to create a schema with concrete type derived from some AbstractType in another xsd.

 The following is my schema meow.xsd. I got the complain:
"src-resolve:Cannot resolve the name 'a:abstractClass' to a(n) 'type definition' component."

at the line: <xs:extension base="a:abstractClass">

Does anyone know what I did wrong here ??? Thanks very much!

meow.xsd
----------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:rules="http://drools.org/rules" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:a="abstractThings" xmlns:f="Things" targetNamespace="Things" elementFormDefault="qualified">

      <xs:import namespace="abstractThings" schemaLocation="rules.xsd" />
      <xs:complexType name="meow1">
            <xs:complexContent>
                  <xs:extension base="a:abstractClass">   -----> wrong here!!!
                        <xs:sequence>
                              <xs:element name="ID" type="String" />
                              <xs:element name="age" type="int" />
                              <xs:element name="weight" type="int" />
                        </xs:sequence>
                  </xs:extension>
            </xs:complexContent>
      </xs:complexType>
</xs:schema>
------------------------------
the original rules.xsd is:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:rules="http://drools.org/rules" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:a="abstractThings" targetNamespace="http://drools.org/rules" elementFormDefault="qualified">
      <xs:element name="rule-set">
            <xs:complexType>
                  <xs:sequence>
                        <xs:element ref="rules:abstractImport" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element ref="rules:application-data" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element ref="rules:abstractFunctions" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element ref="rules:rule" minOccurs="0" maxOccurs="unbounded"/>
                  </xs:sequence>
                  <xs:attribute name="name" type="xs:string" use="required"/>
                  <xs:attribute name="description" type="xs:string"/>
            </xs:complexType>
      </xs:element>
      <xs:element name="rule">
            <xs:complexType>
                  <xs:sequence>
                        <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded">
                              <xs:complexType>
                                    <xs:choice>
                                          <xs:element ref="rules:abstractClass"/>
                                          <xs:element ref="rules:class-field"/>
                                          <xs:element ref="rules:semaphore"/>
                                    </xs:choice>
                                    <xs:attribute name="identifier" type="xs:string" use="required"/>
                              </xs:complexType>
                        </xs:element>
                        <xs:element ref="rules:abstractCondition" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="duration" minOccurs="0">
                              <xs:complexType>
                                    <xs:attribute name="days" type="xs:nonNegativeInteger"/>
                                    <xs:attribute name="hours" type="xs:nonNegativeInteger"/>
                                    <xs:attribute name="minutes" type="xs:nonNegativeInteger"/>
                                    <xs:attribute name="seconds" type="xs:nonNegativeInteger"/>
                              </xs:complexType>
                        </xs:element>
                        <xs:element ref="rules:abstractConsequence"/>
                  </xs:sequence>
                  <xs:attribute name="name" type="xs:string" use="required"/>
                  <xs:attribute name="salience" type="xs:integer"/>
                  <xs:attribute name="no-loop" type="xs:boolean"/>
                  <xs:attribute name="xor-group" type="xs:string"/>
                  <xs:attribute name="description" type="xs:string"/>
            </xs:complexType>
            <!-- All rules must have unique names -->
            <xs:key name="ruleName">
                  <xs:selector xpath="rules:rule"/>
                  <xs:field xpath="@name"/>
            </xs:key>
      </xs:element>
      <xs:element name="class" type="xs:string" substitutionGroup="rules:abstractClass"/>
      <xs:element name="class-field">
            <xs:complexType>
                  <xs:simpleContent>
                        <xs:extension base="xs:string">
                              <xs:attribute name="field" type="xs:string" use="required"/>
                              <xs:attribute name="value" type="xs:string" use="required"/>
                        </xs:extension>
                  </xs:simpleContent>
            </xs:complexType>
      </xs:element>
      <xs:element name="import" type="xs:string" substitutionGroup="rules:abstractImport"/>
      <xs:element name="semaphore">
            <xs:complexType>
                  <xs:attribute name="type" use="required">
                        <xs:simpleType>
                              <xs:restriction base="xs:string">
                                    <xs:enumeration value="String"/>
                                    <xs:enumeration value="Integer"/>
                                    <xs:enumeration value="Long"/>
                                    <xs:enumeration value="Boolean"/>
                                    <xs:enumeration value="Char"/>
                                    <xs:enumeration value="Short"/>
                                    <xs:enumeration value="Float"/>
                                    <xs:enumeration value="Double"/>
                                    <xs:enumeration value="List"/>
                                    <xs:enumeration value="Map"/>
                                    <xs:enumeration value="Set"/>
                              </xs:restriction>
                        </xs:simpleType>
                  </xs:attribute>
            </xs:complexType>
      </xs:element>
      <xs:element name="application-data">
            <xs:complexType>
                  <xs:simpleContent>
                        <xs:extension base="xs:string">
                              <xs:attribute name="identifier" type="xs:string" use="required"/>
                        </xs:extension>
                  </xs:simpleContent>
            </xs:complexType>
      </xs:element>
      <!-- Abstract Definitions for sementic to create concrete implementations -->
      <xs:element name="abstractImport" type="xs:anyType" abstract="true"/>
      <xs:element name="abstractFunctions" type="xs:anyType" abstract="true"/>
      <xs:element name="abstractClass" type="xs:anyType" abstract="true"/>
      <xs:element name="abstractClassField" type="xs:anyType" abstract="true"/>
      <xs:element name="abstractCondition" type="xs:anyType" abstract="true"/>
      <xs:element name="abstractConsequence" type="xs:anyType" abstract="true"/>
</xs:schema>

0
meow00
Asked:
meow00
  • 5
  • 4
1 Solution
 
Geert BormansCommented:
Hi meow00,
> <xs:import namespace="abstractThings" schemaLocation="rules.xsd" />

this namespace needs to be the target element of the imported rules.xsd

try
<xs:import namespace="http://drools.org/rules" schemaLocation="rules.xsd" />
 
Cheers!
0
 
meow00Author Commented:
... but this morning I just noticed that "http://drools.org/rules" was recently removed ...
in this case, what should I put in the namespace ? thanks.


I still tried the above way <xs:import namespace="http://drools.org/rules" schemaLocation="rules.xsd" />

but I got errors at the same line:
src-resove.4.2: error resolving component "a:abstractClass". It was detected that "a:abstractClass" is in namespace "abstractThings", but the component from this namespace is not referenceable from schema document 'file:C// ....//meow.xsd". If this is the incorrect namespace, perhaps the prefix of "a:abstractClass" needs to be changed. If this is the correct namespace, then an appropriate "import" tag should be added to file:"C:// ... /meow.xsd".

What does the above error message mean ? Thanks.
0
 
Geert BormansCommented:
you have two problems,
first the imported namespace should be the target namespace of that imported namespace, as I said
this also means that you cannot use the namespace referenced in the imported schema,
but that is no problem since it is not used, then you also have to refernce to the correct namespace
... in short, your namespace a: should also point to rules, like this

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:rules="http://drools.org/rules" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:a="http://drools.org/rules" xmlns:f="Things" targetNamespace="Things" elementFormDefault="qualified">
   
    <xs:import namespace="http://drools.org/rules" schemaLocation="rules.xsd" />
    <xs:complexType name="meow1">
        <xs:complexContent>
            <xs:extension base="a:abstractClass">
                <xs:sequence>
                    <xs:element name="ID" type="String" />
                    <xs:element name="age" type="int" />
                    <xs:element name="weight" type="int" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>

your second problem is that abstractClass is not a type, but an element

abstract types require derivation by restriction or extension
abstract elements require substitution groups
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
meow00Author Commented:
thanks very much ...

 May I have an example if I want to have a concrete element derived from that "abstractClass" ...
I am really confused about where to start ... please help! Many thanks!
0
 
Geert BormansCommented:
meow00,

here is a substitution group defined

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:rules="http://drools.org/rules"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:a="http://drools.org/rules"
    xmlns:f="Things"
    targetNamespace="Things"
    elementFormDefault="qualified">
    <xs:import namespace="http://drools.org/rules" schemaLocation="rules.xsd" />
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
                <xs:element ref="a:abstractClass"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="gender" substitutionGroup="a:abstractClass">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:enumeration value="Male"/>
                <xs:enumeration value="Female"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="dayTime" substitutionGroup="a:abstractClass">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:enumeration value="Day"/>
                <xs:enumeration value="Night"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
</xs:schema>

both gender and dayTime are elements of the substitutiongroup for a:abstractClass
this means they can replace a:abstractClass elements where they occur
eg in root
since the abstractClass has a abstract attribute, it can't be in there itself

here is a valid XML for the above schema

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="Things"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="Things root.xsd">
    <dayTime>Day</dayTime>
    <gender>Male</gender>
</root>

hope this makes sense

the abstract class on types is much easier to understand

cheers
0
 
meow00Author Commented:
That does help a lot! Thanks so much!

Sorry I have one more question:
What if the derived concrete class I need is something like:

<xs:element name="Dogs" substitutionGroup="a:abstractClass">
            <xs:simpleType>
                  <xs:restriction base="xs:string">
                              <xs:element name="puppyName" type="String" />
                              <xs:element name="age" type="int" />
                              <xs:element name="weight" type="int" />
                  </xs:restriction>
           </xs:simpleType>
      </xs:element>
-----------------------------------------------
  I tried to modify your code to the above thing, because I want that a Dog class with several string and int attributes
....but it doesn't work ...
 I tried to change the code to complexType ... doesn't it work either ...

 Could you please tell me what I did wrong in this case ??? thanks.
0
 
Geert BormansCommented:
        <xs:simpleType>
               <xs:restriction base="xs:string">
                         <xs:element name="puppyName" type="String" />
a simple type can't have child elements, so that will not work

a complexType requires a sequence or a choice
here is what you need

    <xs:element name="Dogs" substitutionGroup="a:abstractClass">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="puppyName" />
                <xs:element name="age"  />
                <xs:element name="weight" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

and the valid XML
<root xmlns="Things"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="Things root.xsd"
    xmlns:th="Things">
    <dayTime>Day</dayTime>
    <gender>Male</gender>
    <Dogs>
        <th:puppyName>woef</th:puppyName>
        <th:age>5</th:age>
        <weight>10</weight>
    </Dogs>
</root>
0
 
meow00Author Commented:
<xs:element name="Dogs" substitutionGroup="a:abstractClass">
            <xs:complexType>
                  
                              <xs:attribute name="puppyName" type="xs:string" />
                              <xs:attribute name="age" type="xs:int" />
                              <xs:attribute name="weight" type="xs:int" />
                  
           </xs:complexType>
      </xs:element>

//--------------------------
I didn't get a complain above, am I correct ? thanks.
0
 
Geert BormansCommented:
if you want it to be attributes, you are correct
cheers
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now