【问题标题】:Not getting whole tag value when include "," in tag value using apache.commons.configuration.tree.ConfigurationNode.getValue()使用 apache.commons.configuration.tree.ConfigurationNode.getValue() 在标签值中包含“,”时未获取整个标签值
【发布时间】:2015-12-18 21:05:19
【问题描述】:

我正在尝试使用 Apache commons 配置读取 xml

这是我的示例 xml 文件

<tu tuid="chan@">
        <note>Label for iCare OLTP administration.</note>
        <prop type="maxlength">75</prop><prop type="minlength">1</prop>
        <tuv lang="ES-ES">
               <seg>Programa, tarjetas, cupones y reglas</seg>
        </tuv>
</tu>

这是我的 java 代码:

 List<ConfigurationNode> tuvNode = element.getChildren("tuv");
 List<ConfigurationNode> segNode = tuvNode.get(0).getChildren("seg");                  

 System.out.println(segNode.get(0).getValue());

输出是:

Programa

实际上它正在工作。问题是当它有“,”时,它不会给出其他值。我需要整个值。任何人都可以给出想法。 我的预期输出是:

Programa, tarjetas, cupones y reglas

我真的很感激

谢谢

【问题讨论】:

  • 另外,如果您接受使用另一个xml库,使用java xml非常容易。
  • 这种情况我必须使用这个库。所以我需要如何获取整个值。它正在工作其他字符。问题是如果有“,”它不会返回其他值的其余部分.. .谢谢

标签: java xml xml-parsing apache-commons-config


【解决方案1】:

',' 被解释为值分隔符。

试试这个:

setDelimiterParsingDisabled(true); //  to disable parsing list of properties.

更多细节在这里: apache commons configuration loads property until "," character

【讨论】:

  • 第一个链接失效 (commons.apache.org/configuration/apidocs/org/apache/commons/…) 请给出正确的链接。非常感谢
  • 我必须在哪里设置这个值 setDelimiterParsingDisabled(true);这是示例代码 snip config = new XMLConfiguration(filename);节点 node = config.getRoot(); List bodyTag = node.getChildren("body"); List elementsInBodyTag = bodyTag.get(0).getChildren();....... List tuvNode = element.getChildren("tuv"); List segNode = tuvNode.get(0).getChildren("seg"); String segNodeVal = segNode.get(0).getValue();谢谢
  • config = new XMLConfiguration(filename); config.setDelimiterParsingDisabled(true);我做了 SetDekimiter 真的。但它不起作用..任何方式都非常感谢您的想法并等待您的回复
【解决方案2】:

@guillaume girod-vitouchkina 感谢您的想法

我们已经设置了这样的值 初始化不带参数的配置对象

config = new XMLConfiguration();

然后禁用分隔符

config.setDelimiterParsingDisabled(true);

然后给出xml文件名

config.load(filename);

在剩下的代码之后

有用的链接doc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    • 2012-05-26
    • 2023-04-04
    • 2012-11-02
    相关资源
    最近更新 更多