1

我有一个如下创建的 xsd 文件,在 Eclipse 中没有错误:

<?xml version="1.0"?>
<xs:schema id="build-summaries" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           elementFormDefault="qualified">
  <xs:element name="build-summaries" >
    <xs:complexType>
      <xs:choice minOccurs="0" 
                 maxOccurs="unbounded">
        <xs:element name="build">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="project-name" 
                          type="xs:string" 
                          minOccurs="0" />
              <xs:element name="label"  
                          type="xs:string" 
                          minOccurs="0" />
              <xs:element name="build-date"  
                          type="xs:string"  
                          minOccurs="0" />
              <xs:element name="log-file"  
                          type="xs:string"  
                          minOccurs="0" />
              <xs:element name="label-dirty"  
                          minOccurs="0"  
                          maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="message"  
                                type="xs:string"  
                                minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="tests"  
                          minOccurs="0"  
                          maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="total"  
                                type="xs:string"  
                                minOccurs="0" />
                    <xs:element name="failed"  
                                type="xs:string"  
                                minOccurs="0" />
                    <xs:element name="error"  
                                type="xs:string"  
                                minOccurs="0" />
                    <xs:element name="clean"  
                                type="xs:string"  
                                minOccurs="0" />
                    <xs:element name="time"  
                                type="xs:string"  
                                minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="summary"  
                          minOccurs="0"  
                          maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="total-tasks"  
                                type="xs:string"  
                                minOccurs="0" />
                    <xs:element name="failures"  
                                type="xs:string"  
                                minOccurs="0" />
                    <xs:element name="status"  
                                type="xs:string"  
                                minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="families"  
                          minOccurs="0"  
                          maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="family"  
                                minOccurs="0"  
                                maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="name"  
                                      type="xs:string"  
                                      minOccurs="0" />
                          <xs:element name="success"  
                                      type="xs:string"  
                                      minOccurs="0" />
                          <xs:element name="failure"  
                                      type="xs:string"  
                                      minOccurs="0" />
                          <xs:element name="notvalid" 
                                      type="xs:string"  
                                      minOccurs="0" />
                          <xs:element name="sar-total"  
                                      type="xs:string"  
                                      minOccurs="0" />
                          <xs:element name="sar-fails"  
                                      type="xs:string"  
                                      minOccurs="0" />
                          <xs:element name="cbuild-tasks"  
                                      type="xs:string"  
                                      minOccurs="0" />
                          <xs:element name="cbuild-fails"  
                                      type="xs:string"  
                                      minOccurs="0" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

我已经使用 xjc jaxb java 类生成器创建了 JAXB 类。现在生成的 JAXB 文件在根元素上有错误:

"Cannot resolve XML element declaration with namespace '' and name 'build-summaries' in this context"

@XmlRootElement(name = "build-summaries")
public class BuildSummaries {

有人可以帮我解决这个问题吗?当我们创建单个 XSD 文件时,我们需要创建命名空间吗?

4

1 回答 1

1

如果您希望 build-summaries 元素位于命名空间中,那么您需要添加targetNamespace="http://example.com/mynamespace"到 xs:schema 元素的开始标签(替换您想要的命名空间的名称http://example.com/mynamespace)。

于 2013-08-12T19:06:52.167 回答