2011-09-21 11 views
7

voglio fare un semplice schema per un elment vuotoerrore durante la convalida dello schema XML

<product orderid="4"/> 

ho creato il mio XSD in questo modo:

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

ottengo il seguente errore durante la convalida XML contro il 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' non è chiuso nel codice precedente, potrebbe essere correlato? – Piskvor

+0

No, è solo un errore nella formulazione, questo codice funziona con me ma dopo aver rimosso "tns" da xmlns: tns = "http://xml.netbeans.org/schema/first", non ho capito il motivo fino ad ora ! – palAlaa

risposta

7

se si cambia XSD e mettere in xmlns="http://xml.netbeans.org/schema/first"xsd:schema e lement dovrebbe funzionare (lo ha fatto per me)

+0

Ottima risposta, omaggio a quella di @jeremyhare. – Gangnus

13

Funzionerà, aggiungendo '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> 

Il prodtype è definito nella targetNamespace dello schema in questo caso 'http://xml.netbeans.org/schema/first'. Per fare riferimento a questo, è necessario includere lo spazio dei nomi in cui è definito. Nell'esempio, si sta tentando di fare riferimento a un prodtype nello spazio dei nomi predefinito che non è definito.

Problemi correlati