javax.xml.bind.UnmarshalException: unexpected element (uri:“”, local:“Group”)

前端 未结 14 1132
终归单人心
终归单人心 2020-12-02 10:13
unexpected element (uri:\"\", local:\"Group\"). Expected elements are <{}group>

Meet an exception when unmarshalling from xml



        
相关标签:
14条回答
  • 2020-12-02 11:01

    You need to put package-info.java in your generated jaxb package. Its content should be something like that

    @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.org/StudentOperations/")
    package generated.marsh;
    
    0 讨论(0)
  • 2020-12-02 11:05

    After looking more, the root element has to be associated with a schema-namespace as Blaise is noting. Yet, I didnt have a package-info java. So without using the @XMLSchema annotation, I was able to correct this issue by using

    @XmlRootElement (name="RetrieveMultipleSetsResponse", namespace = XMLCodeTable.NS1)
    @XmlType(name = "ns0", namespace = XMLCodeTable.NS1)
    @XmlAccessorType(XmlAccessType.NONE)
    public class RetrieveMultipleSetsResponse {//...}
    

    Hope this helps!

    0 讨论(0)
  • 2020-12-02 11:06

    This is a fix for a pretty niche use case but it gets me each time. If you are using the Eclipse Jaxb generator it creates a file called package-info.

    @javax.xml.bind.annotation.XmlSchema(namespace = "blah.xxx.com/em/feed/v2/CommonFeed")
    package xxx.blah.mh.domain.pl3xx.startstop;
    

    If you delete this file it will allow a more generic xml to be parsed. Give it a try!

    0 讨论(0)
  • 2020-12-02 11:08

    If none of the above works, try adding

    @XmlRootElement(name="Group") to the Group classs.

    0 讨论(0)
  • 2020-12-02 11:09

    Luckily, the package-info class isn't required. I was able to fix mine problem with iowatiger08 solution.

    Here is my fix showing the error message to help join the dots for some.

    Error message

    javax.xml.bind.UnmarshalException: unexpected element (uri:"http://global.aon.bz/schema/cbs/archive/errorresource/0", local:"errorresource"). Expected elements are <{}errorresource>

    Code before fix

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name="", propOrder={"error"})
    @XmlRootElement(name="errorresource")
    public class Errorresource
    

    Code after fix

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name="", propOrder={"error"})
    @XmlRootElement(name="errorresource", namespace="http://global.aon.bz/schema/cbs/archive/errorresource/0")
    public class Errorresource
    

    You can see the namespace added to @XmlRootElement as indicated in the error message.

    0 讨论(0)
  • 2020-12-02 11:09

    I already have the same problem and I just change as below:

    @XmlRootElement -> @XmlRootElement(name="Group")
    
    0 讨论(0)
提交回复
热议问题