'Expected element before end of the content. Soap XSD validation
I am using soap and i have response from service. I click right mouse button and choose validate and i have errors 'Expected element xxx before the end of the content..."
In the xsd schema i have already
elementFormDefault="qualified"
AdditionalAtribute as name says is nullable so sometimes it has value but not always. When it has value everything is ok but when it is null my response validation gives me this communicate.
This is what my XSD fragment looks like:
<xsd:element name="listOfThings" maxOccurs="unbounded" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="thingCategory" type="xsd:string" minOccurs="0"/>
<xsd:element name="thingName" type="xsd:string" minOccurs="0"/>
<xsd:element name="thingValue" type="xsd:string" minOccurs="0"/>
<xsd:element name="additionalAttubute" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
XML example
<tns:listOfThings>
<tns:thing>
<tns:thingCategory>CATEGORY</tns:thingCategory>
<tns:thingName>NAME</tns:thingName>
<tns:thingValue>A</tns:thingValue>
</tns:thing>
<tns:thing>
<tns:thingCategory>CATEGORY2</tns:thingCategory>
<tns:thingName>NAME2</tns:thingName>
<tns:thingValue>B</tns:thingValue>
<tns:additionalAttribute>C</tns:additionalAttribute>
</tns:thing>
</tns:listOfThings>
Solution 1:[1]
You have multiple mismatches between your schema and your XML
- You have actually have a node
thingsunderlistOfThingsthat should have the maxoccurs unbounded rather thanlistOfThings - additionalAttubute in the schema <> additionalAttribute in the XML, a spelling mistake in the schema?
Below is what your schema should look like to match that XML
<tns:element name="listOfThings">
<tns:complexType>
<tns:sequence>
<tns:element minOccurs="0" maxOccurs="unbounded" name="thing">
<tns:complexType>
<tns:sequence>
<tns:element minOccurs="0" name="thingCategory" type="tns:string" />
<tns:element minOccurs="0" name="thingName" type="tns:string" />
<tns:element minOccurs="0" name="thingValue" type="tns:string" />
<tns:element minOccurs="0" name="additionalAttribute" type="tns:string" />
</tns:sequence>
</tns:complexType>
</tns:element>
</tns:sequence>
</tns:complexType>
</tns:element>
Solution 2:[2]
Try with empty element:
<tns:listOfThings>
<tns:thing>
<tns:thingCategory>CATEGORY</tns:thingCategory>
<tns:thingName>NAME</tns:thingName>
<tns:thingValue>A</tns:thingValue>
<tns:additionalAttribute></tns:additionalAttribute>
</tns:thing>
<tns:thing>
<tns:thingCategory>CATEGORY2</tns:thingCategory>
<tns:thingName>NAME2</tns:thingName>
<tns:thingValue>B</tns:thingValue>
<tns:additionalAttribute>C</tns:additionalAttribute>
</tns:thing>
</tns:listOfThings>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Bartek |
