【问题标题】:How do I check if a Qname equals something when using StAX?使用 StAX 时如何检查 Qname 是否等于某个值?
【发布时间】:2021-06-19 02:46:28
【问题描述】:

我正在尝试查找名称为帐户的所有标签。我试过这个...

logger.info("The tag is "+name+ " Is this an account? "+name.equalsIgnoreCase("account")+" "+ mapper.writeValueAsString(dmp.diffMain("account", name)));

但是我明白了……

2021-03-22 08:38:20.738  INFO [,,,] 520 --- [           main] com.jgleason.AccountIT              : The tag is {http://refdata.me.com/2011}account Is this an account? false [{"operation":"INSERT","text":"{http://refdata.me.com/2011}"},{"operation":"EQUAL","text":"account"}]

现在我知道我可以解析出{},但有没有更简洁的方法来测试元素名称?

【问题讨论】:

    标签: java stax


    【解决方案1】:

    找到了……

    String name = end.getName().getLocalPart();
    if(name.endsWith("account")){
        ...
    }
    

    【讨论】:

    • 如果是{http://refdata.me.com/2011}NotAnAccount呢?
    • 抱歉,如果您使用 localPart,则不需要结尾
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多