2011-09-21 5 views
7

Я хочу сделать простую схему для пустого elmentОшибка при проверке XML-схемы

<product orderid="4"/> 

Я создал XSD так:

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

Я получаю следующее сообщение об ошибке при проверке XML против 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' не закрыт в вашем вышеуказанном коде, это может быть связано? – Piskvor

+0

Нет, это просто ошибка в формировании, этот код работает со мной, но после удаления «tns» из xmlns: tns = «http://xml.netbeans.org/schema/first», я до сих пор не понял причину ! – palAlaa

ответ

7

Если вы измените XSD и положить xmlns="http://xml.netbeans.org/schema/first" в xsd:schema е lement, он должен работать (это было для меня)

+0

Отличный ответ, бесплатный для @jeremyhare. – Gangnus

13

Это будет работать, добавив к типу «tns:».

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

prodtype определяется в TargetNamespace схемы, в данном случае «http://xml.netbeans.org/schema/first». Чтобы ссылаться на него, вам нужно указать пространство имен, которое определено в. В вашем примере пытаемся ссылаться на prodtype в пространстве имен по умолчанию, которое не определено.

Смежные вопросы