无URI javax.xml.bind.UnmarshalException:意外元素(uri:"",local:" SearchAndList")。预期要素是(无) [英] No URI javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"SearchAndList"). Expected elements are (none)

查看:82
本文介绍了无URI javax.xml.bind.UnmarshalException:意外元素(uri:"",local:" SearchAndList")。预期要素是(无)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法解组我的数据。我收到以下错误:

I am having trouble to unmarshall my data. I got the following error:


错误FsceClient - getDataInMatches中的错误:意外元素
(uri:,local: SearchAndList)。预期元素是(无)
请求参数:+ COUNTRY = US + YR = 2016 + DIV = Ford + WB = 122.0
javax.xml.bind.UnmarshalException:意外元素(uri:,local : SearchAndList)。 com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726)预期元素是(无)

ERROR FsceClient - Error in getDataInMatches : unexpected element (uri:"", local:"SearchAndList"). Expected elements are (none) requested params:+COUNTRY=US+YR=2016+DIV=Ford+WB=122.0 javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"SearchAndList"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726)

这是我的xml文件:

<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>


推荐答案

当XSD架构不包含元素时遇到定义,只包含类定义(即复杂类型)。

This is encountered when the XSD schema does not contain element definitions and only contains class definitions (i.e. complex types).

例如对于此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>

创建的对象工厂是这样的:

The object factory created is like this:

@XmlRegistry
public class ObjectFactory {
   public ObjectFactory() {
   }
   public Foo createFoo() {
        return new Foo();
    }
}

但是这个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类是:

The ObjectFactory class created by JAXB is:

@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);
    }
}

您可以看到JAXBElement包装器创建方法也是添加。使用第二个XSD,unmarshaller在遇到名为foo的标记时知道该怎么做。因此,如果你有一个XSD,添加元素定义以及复杂类型。

You can see that the JAXBElement wrapper creation method is also added. With the second XSD, the unmarshaller knows what to do when it encounters a tag with name "foo". So if you have an XSD, add "element" definitions as well as the complex types.

-----编辑----
样本unmarshaller代码:

----- EDIT---- The sample unmarshaller code:

JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Object result = ((JAXBElement<Object>) jaxbUnmarshaller.unmarshal(stream)).getValue();

这篇关于无URI javax.xml.bind.UnmarshalException:意外元素(uri:&quot;&quot;,local:&quot; SearchAndList&quot;)。预期要素是(无)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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