logger
logger

Reputation: 2053

XML sax parse exception. Invalid content error

This is my Xml

  <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
           xmlns:ch="http://abc.def.com/admin/find/types/v1" 
           targetNamespace="http://abc.def.com/admin/find/types/v1"
         elementFormDefault="qualified" >

         <import namespace="http://esi.osm.com/commonheader/v3" schemaLocation="CommonHeaderV3_3.xsd" />
    ...  
        <xsd:complexType name="SystemConfig">
            <xsd:sequence>
                <element name="System"      type="xsd:int"        minOccurs="1" />
                <element name="NetworkType" type="ch:NetworkType" minOccurs="1" />
                <element name="Location"    type="xsd:string"     minOccurs="0" />
                <element name="Address"     type="xsd:string"     minOccurs="0" />
                <element name="City"        type="xsd:string"     minOccurs="0" />
            </xsd:sequence>
          </xsd:complexType>

       <simpleType name="NetworkType" >
            <restriction base="string">
                <enumeration value="CABLE" />
                <enumeration value="DSL" />
            </restriction>
       </simpleType>

The error I got when I attempted to run my web service is this..

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'ns3:Location'. One of '{"http://abc.def.com/admin/find/types/v1":NetworkType}' is expected.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)

Edit: Java code

    NetworkType networkType= null;
        if(db.getNetworkType().equals("cable")) {
            networkType= NetworkType.fromValue("CABLE");
        } 
        if (db.getNetworkType().equals("dsl")) {
            networkType = NetworkType.fromValue("DSL");
        } 
   ntList.setNetworkType(networkType);
   log.info(networkType); //prints null....

The values that printed for networkType is null but actually i was able to get the db values Actually I found the problem....there are white spaces contained in the db so the values passed are not entirely correct. It ran fine after trim() was added

Upvotes: 0

Views: 604

Answers (1)

kjhughes
kjhughes

Reputation: 111726

Without seeing your XML, from the error message alone it's clear that the parser encountered a ns3:Location element, realized that a preceding, required ch:NetworkType element was not found, and complained about the omission. We can tell that ch:NetworkType is required because your XSD fragment has minOccurs="1" on ch:NetworkType in the content model for SystemConfig.

Upvotes: 1

Related Questions