Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cvc-elt.1: Cannot find the declaration of element 'MyElement'

I'm trying to validate a really simple xml using xsd, but for some reason I get this error. I'll really appreciate if someone can explain me why.

XML File

<?xml version="1.0" encoding="utf-8"?>  <MyElement>A</MyElement> 

XSD File

<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema"         targetNamespace="http://www.example.org/Test"         xmlns:tns="http://www.example.org/Test"         elementFormDefault="qualified">      <simpleType name="MyType">         <restriction base="string"></restriction>     </simpleType>      <element name="MyElement" type="tns:MyType"></element> </schema> 
like image 857
Mitko Mitev Avatar asked Nov 09 '12 15:11

Mitko Mitev


Video Answer


1 Answers

Your schema is for its target namespace http://www.example.org/Test so it defines an element with name MyElement in that target namespace http://www.example.org/Test. Your instance document however has an element with name MyElement in no namespace. That is why the validating parser tells you it can't find a declaration for that element, you haven't provided a schema for elements in no namespace.

You either need to change the schema to not use a target namespace at all or you need to change the instance to use e.g. <MyElement xmlns="http://www.example.org/Test">A</MyElement>.

like image 65
Martin Honnen Avatar answered Oct 05 '22 15:10

Martin Honnen