質問

I am trying to generate the JAXB class file from below XSD

     <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified"   version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="comp:myItems">
            <xsd:complexType>
               <xsd:sequence>
               <xsd:element name="style" type="xsd:string" />
              </xsd:sequence>
           </xsd:complexType>
         </xsd:element>
       </xsd:schema>  

however I get below error while generating the JAXB class file

C:\JAVA\jdk1.6.0_26\bin>xjc.exe myFile.xsd

parsing a schema... [ERROR] s4s-att-invalid-value: Invalid attribute value for 'type' in element 'element'. Recorded reason: UndeclaredPrefix: Cannot resolve 'comp:myItems' as a QName: the prefix 'comp' is not declared. line 2 of file:/C:/JAVA/jdk1.6.0_26/bin/myFile.xsd

Failed to parse a schema.

Error I am getting because the element name is comp:myItems.

Is there any way to generate the JAXB class file from above XSD?
Any help will be very much appreciated.

役に立ちましたか?

解決

The element name specified in the XML Schema must not contain a colon (:). If you want the element to be namespace qualified you need to specify a targetNamespace on the schema element. You will also need to declare this namespace.

<xsd:schema 
    ...
    targetNamespace="http://www.example.com/foo"
    xmlns:comp="http://www.example.com/foo">
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top