Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when validating xml schema

Tags:

xml

schema

I want to make a simple schema for an empty elment

 <product orderid="4"/>

I created my XSD like this:

<?xml version="1.0" encoding="UTF-8"?>


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/first"
xmlns:tns="http://xml.netbeans.org/schema/first"
elementFormDefault="qualified">

<xsd:element name="product" type="prodtype"/>
<xsd:complexType name="prodtype">
        <xsd:attribute name="prodid" type="xsd:integer"/>
</xsd:complexType>

</xsd:schema>

I get the following error when validating the XML against the XSD:

 Error resolving component 'prodtype'. It was detected that 'prodtype' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/D:/Teacher%20assistant%202011/First%20term/web%20services/test%20programs/BpelModule1/src/product.xsd'. If 'prodtype' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'prodtype' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/D:/Teacher%20assistant%202011/First%20term/web%20services/test%20programs/BpelModule1/src/product.xsd'.
like image 566
palAlaa Avatar asked Sep 21 '11 05:09

palAlaa


People also ask

How you will validate XML document using schema?

XML documents are validated by the Create method of the XmlReader class. To validate an XML document, construct an XmlReaderSettings object that contains an XML schema definition language (XSD) schema with which to validate the XML document. The System. Xml.


2 Answers

This will work, adding 'tns:' to the type.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://xml.netbeans.org/schema/first"
    xmlns:tns="http://xml.netbeans.org/schema/first"
    elementFormDefault="qualified">    
    <xsd:element name="product" type="tns:prodtype"/>
    <xsd:complexType name="prodtype">
        <xsd:attribute name="prodid" type="xsd:integer"/>
    </xsd:complexType>    
</xsd:schema>

The prodtype is defined in the targetNamespace of the schema in this case 'http://xml.netbeans.org/schema/first'. In order to reference it you need to include the namespace that is is defined in. In your example to are trying to reference a prodtype in the default namespace which is not defined.

like image 62
jeremyhare Avatar answered Oct 06 '22 03:10

jeremyhare


If you change your XSD and put xmlns="http://xml.netbeans.org/schema/first" in xsd:schema element it should work (it did for me)

like image 45
Milan Aleksić Avatar answered Oct 06 '22 02:10

Milan Aleksić