Reputation: 31
i am getting the error "Cannot find the declaration of element soapenv:Envelope"
Working fine with other xml files xsd..Issue is with the following ones..
My Xml File is :-
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/
/tmp/checkxsd.xsd">
<soapenv:Body>
<ns:getEntitiesByFilterResponse
xmlns:ns="http://services"
xmlns:ax21="http://objects.services/xsd">
<ns:return xsi:type="ax21:EntityObj">
<ax21:entityId>1065798192</ax21:entityId>
<ax21:entityTypeId>4</ax21:entityTypeId>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 001</ax21:elementValue>
<ax21:id>436</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 001</ax21:elementValue>
<ax21:id>100461</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 001</ax21:elementValue>
<ax21:id>400015</ax21:id>
</ax21:methodValues>
</ns:return>
<ns:return xsi:type="ax21:EntityObj">
<ax21:entityId>1065835163</ax21:entityId>
<ax21:entityTypeId>4</ax21:entityTypeId>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 002</ax21:elementValue>
<ax21:id>436</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 002</ax21:elementValue>
<ax21:id>100461</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>Project SoapUI 002</ax21:elementValue>
<ax21:id>400015</ax21:id>
</ax21:methodValues>
</ns:return>
<ns:return xsi:type="ax21:EntityObj">
<ax21:entityId>1317237376</ax21:entityId>
<ax21:entityTypeId>4</ax21:entityTypeId>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue>
<ax21:id>436</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue>
<ax21:id>100461</ax21:id>
</ax21:methodValues>
<ax21:methodValues xsi:type="ax21:ValuePair">
<ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue>
<ax21:id>400015</ax21:id>
</ax21:methodValues>
</ns:return>
</ns:getEntitiesByFilterResponse></soapenv:Body></soapenv:Envelope>
Please Find XSD below : -
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://objects.services/xsd">
<xs:element name="entityId">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:enumeration value="1065798192" />
<xs:enumeration value="1065835163" />
<xs:enumeration value="1317237376" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="entityTypeId" type="xs:byte" />
<xs:element name="methodValues">
<xs:complexType>
<xs:sequence>
<xs:element name="elementValue">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Project SoapUI 001" />
<xs:enumeration value="Project SoapUI 002" />
<xs:enumeration value="CopyTask_project_1448004605927" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="id">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:enumeration value="436" />
<xs:enumeration value="100461" />
<xs:enumeration value="400015" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My java code to validate xsd against xml is as follows : -
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File("/tmp/checkxsd.xsd"));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File("/home/my-pc/MyXMLFile.xml"))
Any help is greatly appreciated. I am stuck with this.
Upvotes: 1
Views: 2192
Reputation: 25034
The message you are seeing almost invariably means the validator is not loading the schema; in turn, this is almost invariably because it can't find it; this in turn is almost always because of some error in specifying the locations of the schema documents to be processed.
Once the over-long lines in your example are broken and the start-tag for the outermost element can be read conveniently without scrolling right and left, one source of your problem (not necessarily the only one) seems clear. What do you believe is the meaning of the attribute-value specification
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/
/tmp/checkxsd.xsd">
(At this point, I expect you either have a head-slap experience or raise your eyebrows in puzzlement. If the latter, I suggest you consult some documentation.)
Upvotes: 1