2011-09-21 16 views
7

Quiero hacer un esquema simple para un Elment vacíoerror al validar el esquema XML

<product orderid="4"/> 

creé mi XSD como esto:

<?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> 

me sale el siguiente error al validar el XML contra el 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'. 
+0

btw, 'xsd: schema' no está cerrado en el código anterior, ¿podría estar relacionado? – Piskvor

+0

No, es solo un error de formateo, este código funciona conmigo, pero después de eliminar "tns" de xmlns: tns = "http://xml.netbeans.org/schema/first", no entendí la razón hasta ahora ! – palAlaa

Respuesta

7

Si cambia de XSD y poner en xmlns="http://xml.netbeans.org/schema/first"xsd:schema correo Debería funcionar (lo hice por mí)

+0

Excelente respuesta, complementaria a la de @jeremyhare. – Gangnus

13

Esto funcionará, añadiendo 'tns:' al tipo.

<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> 

El prodtype se define en el targetNamespace del esquema en este caso 'http://xml.netbeans.org/schema/first'. Para referenciarlo, debe incluir el espacio de nombre que se define en. En su ejemplo, intenta hacer referencia a un prodotipo en el espacio de nombres predeterminado que no está definido.

Cuestiones relacionadas