没有URI javax.xml.bind.UnmarshaleException:意外的元素(URI:“SearchAndList”,local:“SearchAndList”)。预期元素为(无)
我很难解开我的数据。我得到了以下错误: 错误FsceClient-getDataInMatches中出错:意外元素 (uri:,本地:“SearchAndList”)。预期元素为(无) 请求参数:+COUNTRY=US+YR=2016+DIV=Ford+WB=122.0 javax.xml.bind.UnmarshaleException:意外元素(uri:,local:“SearchAndList”)。预期元素为(无) 位于com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726) 这是我的xml文件:没有URI javax.xml.bind.UnmarshaleException:意外的元素(URI:“SearchAndList”,local:“SearchAndList”)。预期元素为(无),java,xml,rest,jaxb,Java,Xml,Rest,Jaxb,我很难解开我的数据。我得到了以下错误: 错误FsceClient-getDataInMatches中出错:意外元素 (uri:,本地:“SearchAndList”)。预期元素为(无) 请求参数:+COUNTRY=US+YR=2016+DIV=Ford+WB=122.0 javax.xml.bind.UnmarshaleException:意外元素(uri:,local:“SearchAndList”)。预期元素为(无) 位于com.sun.xml.internal.bind.v2.runtim
<SearchAndList>
<fvd>
+COUNTRY=US+YR=2016+DIV=Ford+WB=122.0
</fvd>
<sol>
<rsi>
<sType>Ss</sType>
<mHave>true</mHave>
<toAr>0</toAr>
<toAr>0</toAr>
<toAr>22</toAr>
</rsi>
<rsi>
<sType>ssa</sType>
<mHave>true</mHave>
<toAr>77</toAr>
</rsi>
</sol>
<sol>
<rsi>
<sType>sve</sType>
<mHave>false</mHave>
<toAr>0</toAr>
<toAr>21</toAr>
</rsi>
</sol>
</SearchAndList>
+国家=美国+年份=2016+部门=福特+世界银行=122.0
党卫军
真的
0
0
22
ssa
真的
77
sve
假的
0
21
当XSD模式不包含元素定义且仅包含类定义(即复杂类型)时,会遇到这种情况
e、 g.对于这个XSD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="foo">
<xs:sequence>
<xs:element name="bar" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
但是对于这个XSD:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="foo" type="foo" nillable="true"/>
<xs:complexType name="foo">
<xs:sequence>
<xs:element name="bar" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
JAXB创建的ObjectFactory类是:
@XmlRegistry
public class ObjectFactory {
private final static QName _Foo_QNAME = new QName("", "foo");
public ObjectFactory() {
}
public Foo createFoo() {
return new Foo();
}
@XmlElementDecl(namespace = "", name = "foo")
public JAXBElement<Foo> createFoo(Foo value) {
return new JAXBElement<Foo>(_Foo_QNAME, Foo.class, null, value);
}
}
@XmlRegistry
公共类对象工厂{
私有最终静态QName_Foo_QName=新QName(“,“Foo”);
公共对象工厂(){
}
public Foo createFoo(){
返回新的Foo();
}
@xmlementdecl(名称空间=“name=”foo”)
公共JAXBElement createFoo(Foo值){
返回新的JAXBElement(_Foo_QNAME,Foo.class,null,value);
}
}
您可以看到,还添加了JAXBElement包装器创建方法。对于第二个XSD,解组器知道在遇到名为“foo”的标记时该做什么。因此,如果您有一个XSD,请添加“元素”定义以及复杂类型
-----编辑--
示例解组器代码:
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Object result = ((JAXBElement<Object>) jaxbUnmarshaller.unmarshal(stream)).getValue();
JAXBContext-JAXBContext=JAXBContext.newInstance(ObjectFactory.class);
解组器jaxbUnmarshaller=jaxbContext.createUnmarshaller();
对象结果=((JAXBElement)jaxbUnmarshaller.unmarshal(stream)).getValue();
请编辑您的问题,并在XML之外显示您的XML模式。如果我们能看到进行解组的代码,这也会有所帮助。我对web服务方面的东西非常熟悉。我正在使用anotation:这是我的代码:UnmarshallerPool searchAndListPool=null;JAXBContext JAXBContext\u SearchAndList=JAXBContext.newInstance(SearchAndList.class);searchAndListPool=新的解组器工具(最大池大小,jaxbContext\SearchAndList);searchAndListPool.initialize();解组器解组器=null;InputStream in=makeCachedGETServerCall(finalURL);unmarshaller=searchAndListPool.getResource();返回(SearchAndList)解组器。解组器(in)@XmlRootElement(name=“searchAndList”)@XmlAccessorType(XmlAccessType.FIELD)公共类searchAndList扩展ArrayList实现可序列化的{private static final long serialVersionUID=2447564738604L;@XmlElement private String fvd;public searchAndList(){super();}public void setFvd(String fvd){this.fvd=fvd;}公共字符串getFvd(){return fvd;}@xmlement(name=“sol”,type=sol.class)公共列表getSol(){return this;}}}在问题的底部是带阴影的矩形,显示关键字(java、xml、rest、jaxb)。下面是一个“编辑”链接。请使用该链接更改您的问题,并将代码放在那里。正如您所见,代码很难在注释中阅读。请检查并可能接受答案,好吗?
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Object result = ((JAXBElement<Object>) jaxbUnmarshaller.unmarshal(stream)).getValue();