0

so im using xsd 1.1 to use assert in my code, whatever i do , i cant remove the error "Cannot find declaration of element "test1""

this is my code for :

<?xml version="1.0" encoding="utf-8"?>
 <test1>
  <Candidate name="John">61</Candidate> 
  <Candidate name="Sara">24</Candidate> 
  <Candidate name="Bill">15</Candidate>
 </test1>

and this is my xsd with assert and xsd 1.1 extension

<xs:schema xmlns="http://www.mycompany.com/schema/app"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   targetNamespace="http://www.mycompany.com/schema/app"
   elementFormDefault="qualified"
   xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
   vc:minVersion="1.1">
<xs:element name="test1">
<xs:complexType>
   <xs:sequence>
    <xs:element name="Candidate" maxOccurs="unbounded" minOccurs="0">
      <xs:complexType>
        <xs:simpleContent>
          <xs:extension base="xs:byte">  
            <xs:assert test="sum(Candidate)=100"/>
            <xs:attribute type="xs:string" name="name" use="optional"/>
           </xs:extension>
        </xs:simpleContent>
      </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

my goal is that i want to make this xml and xsd valid with each other

kjhughes
  • 106,133
  • 27
  • 181
  • 240

1 Answers1

0

Your XSD targets the targetNamespace="http://www.mycompany.com/schema/app" namespace, yet your XML is in no namespace.

Alternative solutions:

  1. Add xmlns="http://www.mycompany.com/schema/app" to the root element of your XML document, or
  2. Remove targetNamespace="http://www.mycompany.com/schema/app" from xs:schema in your XSD.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • the element still cannot be found even if i removed those tho. – xeno paradox Apr 13 '22 at 17:32
  • Have you explicitly instructed your validator regarding the XSD to use to validate your XML? If not, have you used `schemaLocation` or `noNamespaceSchemaLocation` to provide hints as instructed in the **See also** link? You have to make the connection somehow, and you've not said how you've tried to do so. – kjhughes Apr 13 '22 at 19:10
  • i tried w/o namespace method and with namespace still cant seem to find the element. – xeno paradox Apr 14 '22 at 10:34
  • You didn't answer my questions. We cannot help you further until you do. – kjhughes Apr 14 '22 at 13:01