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'.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With