JAXB Compiling Issue - [ERROR] Property “Any” is already defined

前端 未结 3 1758
旧时难觅i
旧时难觅i 2020-12-06 19:48

I am trying to create JAXB binding for xccdf-1.1.4.xsd which is a standard schema that can be obtain from XCCDF Schema Location

I am currently using EclipseLink MOXy

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 20:52

    You can use an external bindings file to rename one of the any properties.

    binding.xml

    
    
        
            
                
            
        
    
    
    

    XML Schema (schema.xsd)

    Below is a simplified version of your XML schema:

    
    
    
        
            
                
                    
                    
                
            
        
    
    
    

    XJC Call

    Below is how you make an XJC call that leverages an external binding file.

    xjc -b binding.xml schema.xsd
    

    Generated Class (Foo)

    package org.example.schema;
    
    import java.util.*;
    import javax.xml.bind.annotation.*;
    import org.w3c.dom.Element;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "foo", propOrder = {
        "any",
        "any2"
    })
    public class Foo {
    
        @XmlAnyElement(lax = true)
        protected List any;
        @XmlAnyElement
        protected List any2;
    
    
        public List getAny() {
            if (any == null) {
                any = new ArrayList();
            }
            return this.any;
        }
    
        public List getAny2() {
            if (any2 == null) {
                any2 = new ArrayList();
            }
            return this.any2;
        }
    
    }
    
        

    提交回复
    热议问题