user656213
user656213

Reputation: 1083

cvc-complex-type.2.4.a: invalid content was found starting with element 'ProcessDesc'. One of ProcessName expected

I am validating my jaxb object through Validator class. Below is the code I am using to validate jaxb object. But While validating it I am getting this error.

jc = JAXBContext.newInstance(obj.getClass());
source = new JAXBSource(jc, obj);
Schema schema = schemaInjector.getSchema();
Validator validator = schema.newValidator();
validator.validate(source);

ERROR(SAXParseException): cvc-complex-type.2.4.a: invalid content was found starting with element 'ProcessDesc'. One of ProcessName expected

I don't understand what I have done wrong in my xsd which is causing this error. The element defined in my xsd file is below for which I am getting an error.

<xs:schema xmlns:cc="http://www.ms.com/cm.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ms.com/cm.xsd" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:complexType name="Process">
    <xs:sequence>
      <xs:element name="ProcessId" type="xs:int" />
      <xs:element name="ProcessName" type="xs:string" />
      <xs:element name="ProcessDesc" type="xs:string" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

Please help me to solve this. Thank You.

Upvotes: 30

Views: 212231

Answers (7)

Ali Ben Mahmoud
Ali Ben Mahmoud

Reputation: 1

I encountered the same issue and resolved it by adding the statement " maxOccurs="unbounded"" to the xsd blocenter image description here

Upvotes: -1

laune
laune

Reputation: 31300

The XML Schema code

<xs:complexType name="Process">
  <xs:sequence>
    <xs:element name="ProcessId" type="xs:int" />
    <xs:element name="ProcessName" type="xs:string" />
    <xs:element name="ProcessDesc" type="xs:string" minOccurs="0" />
  </xs:sequence>
</xs:complexType>

describes some XML which ought to look like

<proc> <!-- of type Process -->
  <ProcessId>123</ProcessId>
  <ProcessName>procA</ProcessName>
  <ProcessDesc>A funny process</ProcessDesc> <!-- this could be omitted -->
<proc>

But your XML data looks like

<proc> <!-- of type Process -->
  <ProcessId>123</ProcessId>
  <ProcessDesc>A funny process</ProcessDesc>
  <!-- ... don't know what follows -->

If you don't care about the order of Id, Name, Desc you'll have to change the XML schema. Otherwise you'll have to fix the XML (which is easier).

If you think that "any order of elements" is a good idea, use:

<xs:complexType name="Process">
  <xs:all>
    <xs:element name="ProcessId" type="xs:int" />
    <xs:element name="ProcessName" type="xs:string" />
    <xs:element name="ProcessDesc" type="xs:string" minOccurs="0" />
  </xs:all>
</xs:complexType>

Upvotes: 42

Mohit Singh
Mohit Singh

Reputation: 6187

These kind of errors are due to one of the following reason

  1. Element name is mistyped.
  2. Element not described in the schema is trying to be used.
  3. Elements are in an incorrect order.
  4. Namespace definitions declared either in the root tag or a parent element doesn't match with the prefix (or no prefix) used in the element.
  5. Java object has a null field required in XSD

Upvotes: 14

Ankit Jindal
Ankit Jindal

Reputation: 4050

I got this issue fixed in ITR Utility software (as mentioned in incomeTaxReturnUtilities)

Some fields were filled mistakenly in this section: audit-report

If filled we need to enter section code, date etc all details else left un-filled.

Upvotes: 0

Zon
Zon

Reputation: 19918

Another option is constraint violations when you set a field as required and it's NULL in a record. Check your XSD's minOccurs element property.

Upvotes: 0

tituspenaligom
tituspenaligom

Reputation: 52

This is a simple XSD validation error ... w3c

Upvotes: 0

Xstian
Xstian

Reputation: 8282

If you use a sequence you must keep the order of each element

Definition and Usage The sequence element specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times.

see here

Upvotes: 1

Related Questions