How to deal with JAXB ComplexType with MixedContent data?

前端 未结 2 1040
说谎
说谎 2020-12-01 16:59

I got this XML structure:


  0.00
  
     17.5% No         


        
2条回答
  •  独厮守ぢ
    2020-12-01 17:36

    As you mentioned you need to add the mixed attribute to indicate that your type supports mixed content. Without this specified your XML content is invalid:

    
        
            
        
        
    
    

    The generated TaxDescriptionType class will have the following property. Essentially this means that all of the non-attribute content will be stored in a List. This is necessary because you need a mechanism that indicates where the text nodes are wrt the element content.

    @XmlElementRef(name = "ShortName", namespace = "http://www.example.org/schema", type = JAXBElement.class)
    @XmlMixed
    protected List content;
    

    You will populate this list with instances of String (representing text nodes) and JAXBElement (representing element content).


    ALTERNATIVELY

    Mixed content generally makes life more complicated than it needs to be. If possible I would recommend an alternate XML representation.

    
      0.00
      
        17.5% Non-Recoverable
      
    
    

    Or

    
      0.00
      
        17.5% Non-Recoverable
        vatspecial
      
    
    

提交回复
热议问题