Question

This is xsd file

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://www.example.org/onetext"
        xmlns:tns="http://www.example.org/onetext" 
        elementFormDefault="qualified">
  <element name="edge">
    <complexType>
      <attribute name="x" type="float"></attribute>
      <attribute name="y" type="float"></attribute>
      <attribute name="height" type="float"></attribute>
      <attribute name="width" type="float"></attribute>
      <attribute name="xhref" type="string"></attribute>
      <attribute name="id" type="string"></attribute>
      <attribute name="isLocked" type="string"></attribute>
      <attribute name="rx" type="double"></attribute>
      <attribute name="ry" type="float"></attribute>
      <attribute name="rotation" type="float"></attribute>
    </complexType>
  </element>
</schema>

This is xml file ,

<?xml version="1.0" encoding="UTF-8"?>
<edge xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns="http://www.example.org/onetext"
      xmlns:web="http://www.example.org/onetext"
      xsi:schemaLocation="web_one/WebContent onetext.xsd"
      id="WebApp_ID" version="3.0">
  <image x="336" 
         y="52" 
         height="57.6" 
         width="57.6"
         xhref="/dccp_repository/dam/logo/images/accc_logo.jpg" 
         id="Image_3"
         isLocked="false" 
         rx="336" 
         ry="52" 
         rotation="0" />
</edge>

I faced this kind of problem.

No grammar constraints (DTD or XML schema) detected for the document.

in xml document.

If I changed root node of xml file like given below

<edge xmlns="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:web="web_one/WebContent/onetext.xsd"
      xsi:schemaLocation="web_one/WebContent  
                          web_one/WebContent/onetext.xsd"
      id="WebApp_ID" 
      version="3.0">

then I faced this kind of error

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

I confused with this concept. Please help.

Was it helpful?

Solution

The schema document you show declares an element named edge in the namespace http://www.example.org/onetext (the value of the targetNamespace attribute on the schema element). So far, so good.

In your first XML document instance, the outermost element is named edge, and it is in the namespace http://www.example.org/onetext. That's consistent with the declaration in the schema document. So far, so good. If you invoke an XSD validator telling it to use your schema document to find declarations for elements in the http://www.example.com/onetext namespace, all should be well and the validator should be able to validate your document. When it does, it will tell you that edge elements are declared as having no children, so the edge element in the document instance is not valid, because it has a child named image (in the namespace http://www.example.org/onetext). The validator may also mention that the schema has no declaration for any element named image in that namespace. When you get these error messages, your current problem will be solved and you can get on to the next problem of making your schema and your XML agree on the data format you are defining and using.

But at the moment, that is not happening. Why not? In your first XML instance, your outermost element has xsi:schemaLocation="web_one/WebContent onetext.xsd". Translated into English, this means "Hello, schema validator. If you are looking for schema declarations for elements in the namespace web_one/WebContent, you will find a schema document for that namespace at the location onetext.xsd. Have a nice day!" (Well, the spec doesn't actually say anything about having a nice day; that's just my interpretation.) There are a few things wrong with this:

  1. The string web_one/WebContent is not an absolute URI, so it is not appropriate as a namespace name.
  2. The elements in the document instance both are in namespace http://www.example.org/onetext, and your xsi:schemaLocation attribute tells the schema validator nothing about where to find declarations for that namespace.
  3. If the validator actually reads the schema document onetext.xsd, and if that is the schema document you are showing us, then the validator ought to complain that the namespace name web_one/WebContent does not match the target namespace of the schema document.

The error message you're getting (No grammar constraints ... detected for the document) reflects point 2: your validator is not finding any declarations for the only namespace relevant to your instance document.

The way to correct this is to replace your current xsi:schemaLocation attribute value specification with something like xsi:schemaLocation = "http://www.example.org/onetext onetext.xsd" (assuming that the document onetext.xsd is the schema document you show us, and that it's in the same directory as the document instance being validated -- otherwise, use a correctly formulated relative URI).

Your second XML instance document contains an edge document in namespace http://www.w3.org/2001/XMLSchema. The validator doesn't need a pointer to a schema document for this namespace: it's the XSD namespace, and XSD validators typically have the schema for that namespace hard-coded into them. So its error message is not about not finding any schema; instead, the error message is about not finding a declaration for any element named edge in the XSD namespace.

The change made in the second XML instance can seem plausible only to someone who does not really understand XML namespaces or XML namespace declarations. So it allows me to suggest that what you really need to do is spend an hour or two learning how namespaces work in XML and how a parser understands from your document what (namespace-name, local-name) pair to associate with each element and attribute. Once you do that, many things relating to XSD schemas (in particular, many error messages) will be somewhat less mysterious.

Good luck!

OTHER TIPS

 This is how XML look

 <element>
 <complextype name="edge">
         <height>some words here</height>
         <width>some words here</width>
  </complextype>
 </element>

 Tips: the <element> is the root and does not need a.   name.
 <complextype> is the one u can add name to which is the Child.
 The <height> does not need much styling except  you want to use  DTD for your styling
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top