JAXB marshalling problem - probably namespace related

前端 未结 1 898
庸人自扰
庸人自扰 2020-12-12 02:44

Given the intitial XML (BPEL) file:

 


        
相关标签:
1条回答
  • 2020-12-12 03:24

    If you use the MOXy JAXB implementation you can do the following:

    Your domain objects:

    package example;
    
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement
    public class Process {
    
    }
    

    Use that package annotation @XmlSchema

    @javax.xml.bind.annotation.XmlSchema( 
        namespace = "http://www.example.org", 
        xmlns = {
            @javax.xml.bind.annotation.XmlNs(prefix = "xsd", namespaceURI = "http://www.w3.org/2001/XMLSchema"),
        },
        elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
    package example;
    

    To use MOXy JAXB you need to add a jaxb.properties file in with your model classes with the following entry:

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    This will produce the XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <process xmlns="http://www.example.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
    
    0 讨论(0)
提交回复
热议问题