There are many reasons for this error: - a wrong element given - an element is missing or - there is an unwanted element present at the location of the error message. - element is in invalid name
Notice! This page describes the nature of the error using a hypothetical example and not the erroneous data of the input test file. You should however be able to apply this information to your error case.
There are many reasons for this error. The longer explanations are below, but shortly this error is
- a wrong element given,
- an element is missing or
- there is an unwanted element present at the location of the error message.
- element is in invalid namespace
Explanation of the error message 1:
"Element 'elem1': Missing child element(s). Expected is( elem2 )."
Where elem1 corresponds to the location where the error was detected, and elem2 is the child element missing.
Explanation of the error message 2:
Element 'elem3': This element is not expected. Expected is ( elem4 )
This could practically mean some of the following cases:
The element name was misspelled. Here the element was intended to be elem4, but for some reason it was typed as elem3. Check spelling.
elem4 is defined mandatory in the xml schema the file is trying to be validated against, but it can't be found in the xml file itself. There may not necessarily be anything wrong with elem3, other than the fact that something is missing before it. So elem3 is only where you should be looking for in order to pinpoint the location where the element, in this case elem4, is missing.
It could also be that there is a mandatory element missing before elem3. In this case listed element elem4 could be one of the elements which are allowed to be before the other mandatory element, not mentioned in the error message. An example below next to the picture:
There is a limit for elem3 instances and you have used more than allowed.
Mandatory elements here are: StrtNm, PstCd, TwnNm and Ctry. If you used only Ctry:
The error message would be like this:
Element 'Ctry': This element is not expected. Expected is one of ( AdrTp, AdrLine, StrtNm ).
Meaning that the validator is expecting a mandatory element (StrtNm), and the other two elements listed are optional and can be used before it.
Explanation of the error message 3:
Element 'elem5': This element is not expected.
Where elem5 is an element that is not allowed to be at this location. As in the previous case, the error could be caused by a typing error or a missing mandatory element.
Additionally, the error could originate from a situation where there is a set of choice type of elements (only one can be used at a time) defined in the xml schema, and more than one of them are being used in the xml instance.