简体   繁体   English

Android SimpleXML解析似乎在深度上受到限制

[英]Android SimpleXML Parsing seems limited in Depth

I'm trying to read a config file on Android using Retrofit and SimpleXML. 我正在尝试使用Retrofit和SimpleXML在Android上读取配置文件。

I have my dependencies set up and a valid XML scheme. 我已经设置了依存关系和有效的XML方案。 Simple XML begins to parse my document but when it reaches a certain tag/depth it fails with the error below 简单的XML开始解析我的文档,但是当它达到某个标签/深度时,它将失败并显示以下错误

Caused by: retrofit.converter.ConversionException: org.simpleframework.xml.core.ElementException: Element 'Host' does not have a match in class
Caused by: org.simpleframework.xml.core.ElementException: Element 'Host' does not have a match in class

Part of my xml looks like this: 我的xml的一部分看起来像这样:

<Config>
    ...
    <Identity>
        <Address>
            <Host>...</Host>
            ...
        </Address>
        ...
     </Identity>
     ...
</Config>

It parses everything up until it reaches the Host tag which is the first element nested that deeply. 它解析所有内容,直到到达Host标签为止, Host标签是嵌套在其中的第一个元素。 The error given usually indicates a missing annotation, but the in this case it is annotated as it should be. 给出的错误通常表示缺少注释,但是在这种情况下,应按原样对其进行注释。 My mapped object looks like the following: 我的映射对象如下所示:

@Root(name="Config")
public class Config {

    @ElementList(entry="Identity", inline=true)
    private List<Identity> mIdentities;

    @Root(name="Identity")
    static class Identity {

        @Element(name="Address")
        private Address mAddress;

        ...

    }

    @Root(name="Address")
    static class Address {

        @Element(name="Host")
        private String mHost;

        ...
    }
}

Is there anybody else who has experienced a similar issue and has an idea what the problem may be? 是否还有其他人遇到过类似的问题并且知道可能是什么问题? Or is SimpleXML limited with the depth it can reach? 还是SimpleXML受其可以达到的深度限制? Maybe it's an issue related to ListElement's? 也许这是与ListElement有关的问题? I can't find any documentation that mentions any issues. 我找不到任何提及任何问题的文档。

This exception indicates a missing annotation or a wrong mapping between class and xml. 此异常表示缺少注释类与xml之间的映射错误。 Maybe the nesting is not correct, a wrong annotation is used etc. 也许嵌套不正确,使用了错误的注释等。

It's hard to say whats the cause here, but put make sure your code looks something like this: 很难在这里说出原因是什么,但是请确保您的代码看起来像这样:

(Pseudocode, not testet!) (伪代码,而不是睾丸!)

@Root(name = "Address")
public class Address
{
    @Element(name="Host")
    private String mHost;

    // more things here ...
}

Can you test your problem on a minimal or show at least how address is implemented? 您能否至少测试一下您的问题,或者至少显示地址的实现方式? Btw. 顺便说一句。 is always helpful to try the opposite direction : Take a Config object, serialize it and check if it's constructed as you require. 尝试相反的方向总是很有帮助的:取一个Config对象,对其进行序列化,然后检查它是否按您的要求构造。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM