Reputation: 1241
I read some similar questions posted but still couldn't resolve my issue.
src-resolve: Cannot resolve the name 'at:AutomaticTask' to a(n) 'element declaration' component.
I have main.xsd import task.xsd like bellow.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:at="http://my.sample.com/bpmn" targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL" elementFormDefault="qualified">
<xs:import namespace="http://my.sample.com/bpmn" schemaLocation="task.xsd" />
<xs:element name="definitions">
<xs:complexType>
<xs:sequence>
<xs:element name="userTask">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="extensionElements">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="at:AutomaticTask" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And my task.xsd is as follow. Both xsd files in same folder under test/resoures and I am writing unit test.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://my.sample.com/bpmn"
xmlns="http://my.sample.com/bpmn"
elementFormDefault="qualified">
<xs:element name="AutomaticTask">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="id" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
here is the xml to validate.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:at="http://my.sample.com/bpmn">
<userTask id="123xb" name="task1">
<extensionElements>
<at:automaticTask name="myTask" id="0318ba00" />
</extensionElements>
<incoming>SequenceFlow_1x3hpv4</incoming>
<outgoing>SequenceFlow_02ko1r6</outgoing>
</userTask>
</definitions>
Upvotes: 0
Views: 2715
Reputation: 111591
Change xs:schema/@targetNamespace
in the imported XSD (task.xsd
) from my.sample.com/bpmn
to http://my.sample.com/bpmn
to match the value given by the xmlns:at
namespace prefix declaration and xs:import/@namespace
in the importing XSD (main.xsd
).
Here are your XSDs repaired to eliminate the error:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:at="http://my.sample.com/bpmn"
targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL"
elementFormDefault="qualified">
<xs:import namespace="http://my.sample.com/bpmn" schemaLocation="task.xsd" />
<xs:element name="definitions">
<xs:complexType>
<xs:sequence>
<xs:element name="userTask">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="extensionElements">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="at:AutomaticTask" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://my.sample.com/bpmn"
xmlns="http://my.sample.com.com/bpmn"
elementFormDefault="qualified">
<xs:element name="AutomaticTask">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="id" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
Update:
The following repaired XML file is now valid per the above XSDs:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:at="http://my.sample.com/bpmn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL
try.xsd">
<userTask id="123xb" name="task1">
<extensionElements>
<at:AutomaticTask name="myTask" id="0318ba00" />
</extensionElements>
<!-- incoming and outgoing are not defined in your XSD:
<incoming>SequenceFlow_1x3hpv4</incoming>
<outgoing>SequenceFlow_02ko1r6</outgoing>
-->
</userTask>
</definitions>
Upvotes: 2