当前位置: 代码迷 >> XML/SOAP >> 怎样处理小弟我的xml文件中的特定字段
  详细解决方案

怎样处理小弟我的xml文件中的特定字段

热度:339   发布时间:2012-03-24 14:00:46.0
怎样处理我的xml文件中的特定字段?
XML code
  <defaultSlice>
    <axes>
      <axis name="rows">
        <hierarchy sort="unsorted">
          <dimensionName>[Customer]</dimensionName>
          <hierarchyName>[Customer].[City]</hierarchyName>
        </hierarchy>
      </axis>
      <axis name="columns">
        <hierarchy sort="asc">
          <dimensionName>[Customer]</dimensionName>
          <hierarchyName>[Customer].[Country]</hierarchyName>
          <filter>
            <member><![CDATA[[Customer].[Country].&[#temp]]]></member>
          </filter>
        </hierarchy>
        <hierarchy>
          <dimensionName>[Measures]</dimensionName>
          <hierarchyName>[Measures]</hierarchyName>
        </hierarchy>
      </axis>
      <axis name="pages"/>
    </axes>
    <measures>
      <measure aggregation="sum">[Measures].[Internet Sales Amount]</measure>
    </measures>
  </defaultSlice>

我现在怎么才能把我的:
XML code
<filter>
            <member><![CDATA[[Customer].[Country].&[#temp]]]></member>
          </filter>
里边的值#temp,替换我想要的值Canada呀?

------解决方案--------------------
Java code

package csdn.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class Test {

    public static void main(String[] args) throws DocumentException {
        String xml = "<?xml version='1.0' encoding='utf-8'?>"
                + "<filter>"
                + "<member><![CDATA[[Customer].[Country].&[#temp]]]></member></filter>";
        Document doc = DocumentHelper.parseText(xml);
        Element rootEle = doc.getRootElement();
        String member = rootEle.selectSingleNode("/filter/member").getText();
        member = member.replaceAll("#temp", "Canada");
        System.out.println(member);
    }
} 
  相关解决方案