解组工作不正确:javax.xml.bind.UnmarshalException:意外元素 [英] Unmarshalling works incorrectly: javax.xml.bind.UnmarshalException: unexpected element

查看:155
本文介绍了解组工作不正确:javax.xml.bind.UnmarshalException:意外元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有异常

javax.xml.bind.UnmarshalException: unexpected element 
(uri:"", local:"ConnectorCommandType")

尝试unmarshall xml,如下所示:

trying to unmarshall xml, shown below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
  <ConnectorCommandType> ........ </ConnectorCommandType>

该异常基本上表示在jaxb上下文中找不到该元素。但调试显示此类在当前jaxb上下文中存在且已知。 ConnectorCommandType类是从xsd xml生成的< xs:complexType> 元素。

The exception basically says that element is not found in jaxb context. But debugging shows that this class is present and known in current jaxb context. The class ConnectorCommandType was generated from xsd xml as <xs:complexType> element.

xsd会出错吗?

有没有人遇到这样的问题?有什么建议?谢谢。

Has anyone faced with problem like that? Any suggestions? Thanks.

推荐答案

解决方案取决于以下问题的答案:

The solution depends on the answer to the following question:

ConnectorCommandType 类上是否有 @XmlRootElement(name =ConnectorCommandType)注释,或者 ObjectFactory 类中的create方法上的 @XmlElementDecl(name =ConnectorCommandType)

Is there an @XmlRootElement(name="ConnectorCommandType") annotation on the ConnectorCommandType class, or an @XmlElementDecl(name="ConnectorCommandType") on a create method in the ObjectFactory class?

如果答案是肯定

是否有 package-info 吗?看起来好像是你的 JAXB(JSR-222) 实现期望命名空间限定文档。类似于:

Is there a package-info in your generated model? It appears as though your JAXB (JSR-222) implementation is expecting a namespace qualified document. Something like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCommandType xmlns="YOUR_NAMESPACE_HERE">
     ........ 
</ConnectorCommandType>

更多信息

  • http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
  • http://blog.bdoughan.com/2012/07/jaxb-and-root-elements.html

如果答案为否

如果 ConnectorCommandType 元素不是与类关联,那么你将需要
使用一个带有类参数的unmarshal方法。

If the ConnectorCommandType element is not associated with a class, then you will need to use one of the unmarshal methods that takes a class parameter.

  • http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Unmarshaller.html#unmarshal%28javax.xml.stream.XMLStreamReader,%20java.lang.Class%29

这篇关于解组工作不正确:javax.xml.bind.UnmarshalException:意外元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆