sunesh amarasinghe
sunesh amarasinghe

Reputation: 1

cvc-elt.1: Cannot find the declaration of element 'Root'

XSD Sample

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderperson" type="xs:string" />
      <xs:element name="name" type="xs:string" />
      <xs:element name="address" type="xs:string" />  
    </xs:sequence>
    <xs:attribute name="orderid" type="xs:string" />
  </xs:complexType>
</xs:element>
</xs:schema>

XML response Sample

<?xml version="1.0" encoding="utf-8"?>
<shiporder orderid="str1234">
  <orderperson>str1234</orderperson>
  <name>str1234</name>
  <address>str1234</address>
</shiporder>

Schema Validate Dom Source

http://hostcode.sourceforge.net/view/3307

Schema Validate StreamSource

http://hostcode.sourceforge.net/view/3306

Validating as Stream source works fine. When validating with DomSource I am experience the error. cvc-elt.1: Cannot find the declaration of element 'shiporder'.

What is the reason for this behavior.?

My main question why validator.validate(new DOMSource(node));  does not work in shema validation. What is the reason ?

Upvotes: 0

Views: 1099

Answers (1)

dsnstank
dsnstank

Reputation: 11

During the creation of DOM structure you need to explicitly specify that your DOM elements does not belong to any namespace. You can do this by calling org.w3c.dom.Document#createElementNS instead of org.w3c.dom.Document#createElement, where namespaceURI has null value.

Example: document.createElementNS(null, qualifiedName).

Upvotes: 1

Related Questions