javax.xml.bind.UnmarshalException:意外元素(uri:“”,local:“Managers”)。(javax.xml.bind.UnmarshalException: unexpected element (uri:“”, local:“Managers”). Expected elements are <{}Manager>)

我知道在SO上有很多像这样的问题,但没有一个为我提供正确的答案所以我走了。

这是我得到的XML:

<?xml version="1.0" encoding="UTF-8"?> <Managers> <Manager ManagerID="1996" /> <Manager ManagerID="1997" /> <Manager ManagerID="1998" /> <Manager ManagerID="1999" /> <Manager ManagerID="2000" /> </Managers>

这是相关的java类:

@XmlRootElement(name = "Managers") @XmlAccessorType(XmlAccessType.FIELD) public class ManagerList { @XmlElement(name = "Manager") private List<Manager> Managers = null; public List<Manager> getList() { return Managers; } public void setList(List<Manager> Managers) { this.Managers = Managers; } }

最后这里是解组部分:

String stringManagers = //Here is the above XML(as String), i get it from an external source StringReader reader = new StringReader(stringManagers); JAXBContext context; Unmarshaller un; context = JAXBContext.newInstance(ManagerList.class); un = context.createUnmarshaller(); ManagerList managerList = (ManagerList) un.unmarshal(reader);

我正在使用wsdl2java生成java类,我有一个package-info.java类,其命名空间使用XmlSchema注释定义。

但我仍然得到错误:

javax.xml.bind.UnmarshalException: unexpected element (uri:“”, local:“Managers”). Expected elements are <{}Manager>

任何想法将不胜感激,

提前致谢 !

I know there are a lot of questions like this one on SO but none provided the right answer for me so here i go.

Here is the XML i get :

<?xml version="1.0" encoding="UTF-8"?> <Managers> <Manager ManagerID="1996" /> <Manager ManagerID="1997" /> <Manager ManagerID="1998" /> <Manager ManagerID="1999" /> <Manager ManagerID="2000" /> </Managers>

And here is the java class associated :

@XmlRootElement(name = "Managers") @XmlAccessorType(XmlAccessType.FIELD) public class ManagerList { @XmlElement(name = "Manager") private List<Manager> Managers = null; public List<Manager> getList() { return Managers; } public void setList(List<Manager> Managers) { this.Managers = Managers; } }

And finally here is the unmarshalling part :

String stringManagers = //Here is the above XML(as String), i get it from an external source StringReader reader = new StringReader(stringManagers); JAXBContext context; Unmarshaller un; context = JAXBContext.newInstance(ManagerList.class); un = context.createUnmarshaller(); ManagerList managerList = (ManagerList) un.unmarshal(reader);

I'm using wsdl2java to generate the java classes, and i have a package-info.java class with the namespace defined using XmlSchema annotation.

But still i'm getting the error :

javax.xml.bind.UnmarshalException: unexpected element (uri:“”, local:“Managers”). Expected elements are <{}Manager>

Any idea would be appreciated,

Thanks in advance !

最满意答案

好吧,似乎我最近使用API​​来改变我的XML,即使我使用wsdl2java重新生成类,Eclipse也很难理解。

我只需要清理它,然后用新课程重新开始。

对不起“愚蠢”的问题!

Okay so it seems that the API i use to get my XML changed recently and even if i re-generated the classes using wsdl2java, Eclipse had a hard time understanding that.

I just had to clean it all and start over it with fresh classes.

Sorry for the "dumb" question !

javax.xml.bind.UnmarshalException:意外元素(uri:“”,local:“Managers”)。(javax.xml.bind.UnmarshalException: unexpected element (uri:“”, local:“Managers”). Expected elements are <{}Manager>)

我知道在SO上有很多像这样的问题,但没有一个为我提供正确的答案所以我走了。

这是我得到的XML:

<?xml version="1.0" encoding="UTF-8"?> <Managers> <Manager ManagerID="1996" /> <Manager ManagerID="1997" /> <Manager ManagerID="1998" /> <Manager ManagerID="1999" /> <Manager ManagerID="2000" /> </Managers>

这是相关的java类:

@XmlRootElement(name = "Managers") @XmlAccessorType(XmlAccessType.FIELD) public class ManagerList { @XmlElement(name = "Manager") private List<Manager> Managers = null; public List<Manager> getList() { return Managers; } public void setList(List<Manager> Managers) { this.Managers = Managers; } }

最后这里是解组部分:

String stringManagers = //Here is the above XML(as String), i get it from an external source StringReader reader = new StringReader(stringManagers); JAXBContext context; Unmarshaller un; context = JAXBContext.newInstance(ManagerList.class); un = context.createUnmarshaller(); ManagerList managerList = (ManagerList) un.unmarshal(reader);

我正在使用wsdl2java生成java类,我有一个package-info.java类,其命名空间使用XmlSchema注释定义。

但我仍然得到错误:

javax.xml.bind.UnmarshalException: unexpected element (uri:“”, local:“Managers”). Expected elements are <{}Manager>

任何想法将不胜感激,

提前致谢 !

I know there are a lot of questions like this one on SO but none provided the right answer for me so here i go.

Here is the XML i get :

<?xml version="1.0" encoding="UTF-8"?> <Managers> <Manager ManagerID="1996" /> <Manager ManagerID="1997" /> <Manager ManagerID="1998" /> <Manager ManagerID="1999" /> <Manager ManagerID="2000" /> </Managers>

And here is the java class associated :

@XmlRootElement(name = "Managers") @XmlAccessorType(XmlAccessType.FIELD) public class ManagerList { @XmlElement(name = "Manager") private List<Manager> Managers = null; public List<Manager> getList() { return Managers; } public void setList(List<Manager> Managers) { this.Managers = Managers; } }

And finally here is the unmarshalling part :

String stringManagers = //Here is the above XML(as String), i get it from an external source StringReader reader = new StringReader(stringManagers); JAXBContext context; Unmarshaller un; context = JAXBContext.newInstance(ManagerList.class); un = context.createUnmarshaller(); ManagerList managerList = (ManagerList) un.unmarshal(reader);

I'm using wsdl2java to generate the java classes, and i have a package-info.java class with the namespace defined using XmlSchema annotation.

But still i'm getting the error :

javax.xml.bind.UnmarshalException: unexpected element (uri:“”, local:“Managers”). Expected elements are <{}Manager>

Any idea would be appreciated,

Thanks in advance !

最满意答案

好吧,似乎我最近使用API​​来改变我的XML,即使我使用wsdl2java重新生成类,Eclipse也很难理解。

我只需要清理它,然后用新课程重新开始。

对不起“愚蠢”的问题!

Okay so it seems that the API i use to get my XML changed recently and even if i re-generated the classes using wsdl2java, Eclipse had a hard time understanding that.

I just had to clean it all and start over it with fresh classes.

Sorry for the "dumb" question !