【问题标题】:How to process XML in CDATA section?如何处理 CDATA 部分中的 XML?
【发布时间】:2014-09-07 22:39:01
【问题描述】:

我有这个 XML 部分:

<additionalChargeAttrs><![CDATA[
    <CPEChargeAttrs>
         <complexattributeinfo name =  "Total charge amount" value = "99.00000000"/>
         <complexattributeinfo name =  "Minimum number of installments" value = "3"/>  
         <complexattributeinfo name =  "Maximum number of installments" value = "3"/>  
         <complexattributeinfo name =  "Installment number" value = "1"/>
         <complexattributeinfo name =  "Prorated from date" value = "1960-01-01 19:50:00"/>
         <complexattributeinfo name =  "Prorated to date" value = "2020-12-31 19:50:00"/>
         <complexattributeinfo name =  "Bundle code" value = " "/>
         <complexattributeinfo name =  "Offer subtype" value = "P"/>
         <complexattributeinfo name =  "Installment eligibility" value = "Y"/>
         <complexattributeinfo name =  "NRC charge type" value = "Regular"/>
    </CPEChargeAttrs>
]]></additionalChargeAttrs>

我想使用 JAVA 代码将以下元素(在 CDATA 部分中)的值更改为 3:

<complexattributeinfo name =  "Installment number" value = "1"/>

【问题讨论】:

  • 你试过什么?
  • -1 表示尽快/紧急...

标签: java xml


【解决方案1】:

CDATA 部分的内容是未解析的,这意味着它只是文本 blob。您需要获取该文本 blob 并再次通过 XML 解析器运行它,更改属性值,将文档写入新字符串,并用这个新字符串替换原始 CDATA 内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 2014-03-02
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    相关资源
    最近更新 更多