首页 > 其他分享 >查找xml cdata 节点并去掉 CDATA 节点标记

查找xml cdata 节点并去掉 CDATA 节点标记

时间:2023-05-26 16:12:06浏览次数:40  
标签:xml cdata CDATA data 节点 string

内容如下
<?xml version="1.0" encoding="UTF-8"?>
<transstatus>
    <transname>C-QXZSPJ-QXZSPJ-015-1</transname>
    <id>2ca8df47-3b2d-4d8f-8b70-be68448dd97d</id>
    <status_desc>Finished</status_desc>
    <error_desc/>
    <log_date>2023/05/26 14:36:13.127</log_date>
    <paused>N</paused>
    <stepstatuslist>
        <stepstatus>
            <stepname>tableInputStep</stepname>
            <copy>0</copy>
            <linesRead>0</linesRead>
            <linesWritten>0</linesWritten>
            <linesInput>0</linesInput>
            <linesOutput>0</linesOutput>
            <linesUpdated>0</linesUpdated>
            <linesRejected>0</linesRejected>
            <errors>0</errors>
            <statusDescription>已完成</statusDescription>
            <seconds>0.0</seconds>
            <speed>0</speed>
            <priority>-</priority>
            <stopped>N</stopped>
            <paused>N</paused>
        </stepstatus>
        <stepstatus>
            <stepname>insertUpdateStep</stepname>
            <copy>0</copy>
            <linesRead>0</linesRead>
            <linesWritten>0</linesWritten>
            <linesInput>0</linesInput>
            <linesOutput>0</linesOutput>
            <linesUpdated>0</linesUpdated>
            <linesRejected>0</linesRejected>
            <errors>0</errors>
            <statusDescription>已完成</statusDescription>
            <seconds>0.0</seconds>
            <speed>0</speed>
            <priority>-</priority>
            <stopped>N</stopped>
            <paused>N</paused>
        </stepstatus>
        <stepstatus>
            <stepname>stepsMetricsStep</stepname>
            <copy>0</copy>
            <linesRead>1</linesRead>
            <linesWritten>1</linesWritten>
            <linesInput>0</linesInput>
            <linesOutput>0</linesOutput>
            <linesUpdated>0</linesUpdated>
            <linesRejected>0</linesRejected>
            <errors>0</errors>
            <statusDescription>已完成</statusDescription>
            <seconds>0.2</seconds>
            <speed>5</speed>
            <priority>-</priority>
            <stopped>N</stopped>
            <paused>N</paused>
        </stepstatus>
        <stepstatus>
            <stepname>setVariableStep</stepname>
            <copy>0</copy>
            <linesRead>1</linesRead>
            <linesWritten>1</linesWritten>
            <linesInput>0</linesInput>
            <linesOutput>0</linesOutput>
            <linesUpdated>0</linesUpdated>
            <linesRejected>0</linesRejected>
            <errors>0</errors>
            <statusDescription>已完成</statusDescription>
            <seconds>0.2</seconds>
            <speed>5</speed>
            <priority>-</priority>
            <stopped>N</stopped>
            <paused>N</paused>
        </stepstatus>
    </stepstatuslist>
    <first_log_line_nr>0</first_log_line_nr>
    <last_log_line_nr>2029</last_log_line_nr>
    <result>
        <lines_input>0</lines_input>
        <lines_output>0</lines_output>
        <lines_read>0</lines_read>
        <lines_written>0</lines_written>
        <lines_updated>0</lines_updated>
        <lines_rejected>0</lines_rejected>
        <lines_deleted>0</lines_deleted>
        <nr_errors>0</nr_errors>
        <nr_files_retrieved>0</nr_files_retrieved>
        <entry_nr>0</entry_nr>
        <result>Y</result>
        <exit_status>0</exit_status>
        <is_stopped>N</is_stopped>
        <log_channel_id>fb424211-b0f7-45d1-9fd5-be55785e0c58</log_channel_id>
        <log_text/>
    </result>
    <logging_string>&lt;![CDATA[H4sIAAAAAAAAAK2TW0sCQRTH3/sU57HAy+56eRB8EN1iJS/tJaOQ2NapBnTWdkajt4KQoAJfe6wMX6Jnkfo2avYt2qFaLFxI2XmYYS7n9/9zzhxJkGJRIRGVkiDGU7FkSoxBGLLhrZ1drZz/WQQxERbd89FgOBp2pm/Pk9uHaf/x4643vX8aDS7Gr+fj/jXA3tzA6oo0VwUTihxmNGsmQxpDzYjApW1CkMVQDZgN7o15YFLkA97X1Y0qrFp2o4FZWhLcseaj5XLqSCHNFvOU1jHB9NgVcpBZw+QITlrIOQuBVbcp31pfTrBNIj5Q6qJoATEHW9TDjl9uJlfdce/yvduBVSUthKDEJzUthqDCJ4Nv5bSvV4rYtulg7tijaogxbgqRNnZs0kCEQfv7EY1EfB3OR3mhoOlyuZgpyDzbbbPeclP9tyx+5fsXW8nNkHV+XGoxtwpLQ5XiplKUi0ZhhissTSsZepA4Vc7kguQZ5VxGl4MkVlQlWKAq5+VsoEnMljRdV359yfgiMK+vzUOGHBDBsU/pIg2ySAd/Ao7BUkNABQAA]]&gt;</logging_string>
</transstatus>

获取 cdata

 with open(file_name, 'r') as f:
        xml_string = f.read()
    import xml.etree.ElementTree as ET
    root = ET.fromstring(xml_string)
    for c_data  in root.findall(".//logging_string"):
        data_content =  c_data.text.replace("<![CDATA[", "").replace("]]>", "")
        print(data_content)

标签:xml,cdata,CDATA,data,节点,string
From: https://www.cnblogs.com/guanchaoguo/p/17435002.html

相关文章

  • 动力节点Docker实战入门教程(4)Docker容陈可人
    根据B站上动力节点的最新版Docker教程整理了学习笔记,持续更新中~4Docker容器4.1容器基础4.1.1容器启动流程通过dockerrun命令可以启动运行一个容器。该命令在执行时首先会在本地查找指定的镜像,如果找到了,则直接启动,否则会到镜像中心查找。如果镜像中心存在该镜像,则会下载到本地......
  • FLEX实践—XML、XMLList、XMLListCollection、ArrayCollection关系转换
    在本实例中将从一个XML对象通过层层转换最终变为ArrayCollection对象  <?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">......
  • FLEX AIR实践—FLEX AIR XML Encode Bug
     这几天在用AIR程序通过WebService进行数据传输时发现了以下问题:用WebService传输‘A&B’内容到目的地,再从目的地将数据通过WebService获取到本地,结果数据变成了'A&amp;B';于是开始进行以下测试:将'A&B'替换成'A&amp;B'——>获取结果为'A&amp;amp;B'测试了其他转义字符也得到了同样......
  • FLEX实践—XML HttpService加载错误
    主应用代码:<?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center" verticalAlign="middle" creationComplete="init......
  • FLEX实践—加载XML文件错误
        这两天在研究一个FLEX小相册,准备做一个超级简单的纯FLEX相册,没想到在读取XML文件的时候遇到了这样一个问题:    1)用FLEXBUILDER创建了一个FLEX工程    2)写了一个MXML文件,一个XML文件    3)在程序中用HTTPService和URLRequest两种方法分别读取XML文件内容 ......
  • 2.Redis的安装与配置-动力节点Redis7笔记
    2Redis的安装与配置这里是要将Redis安装到Linux系统中。2.1Redis的安装2.1.1克隆并配置主机修改主机名:/etc/hostname修改网络配置:/etc/sysconfig/network-scripts/ifcfg-ens332.1.2安装前的准备工作2.1.2.1安装gcc由于Redis是由C/C++语言编写的,而从官网下载的Redis......
  • Redis的安装与配置-动力节点最全Redis7笔记
    ##【动力节点】Redis入门到高级教程,全网最新最全redis缓存教程,redis百科大全2Redis的安装与配置这里是要将Redis安装到Linux系统中。2.1Redis的安装2.1.1克隆并配置主机修改主机名:/etc/hostname修改网络配置:/etc/sysconfig/network-scripts/ifcfg-ens332.1.2安装前的......
  • 图解LeetCode——24. 两两交换链表中的节点
    一、题目给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。二、示例2.1>示例1:【输入】head=[1,2,3,4]<br>【输出】[2,1,4,3]2.2>示例2:【输入】head=[]<br>【输出】[]2.3>示例......
  • XML和javaConfig
    1. 为什么要使用 Spring Boot  11. 因为Spring, SpringMVC 需要使用的大量的配置文件 (xml文件)还需要配置各种对象,把使用的对象放入到spring容器中才能使用对象需要了解其他框架配置规则。2. SpringBoot 就相当于 不需要配置文件的Spring+SpringMVC。 常用的框架和第三......
  • 力扣---450. 删除二叉搜索树中的节点
    给定一个二叉搜索树的根节点root和一个值key,删除二叉搜索树中的 key 对应的节点,并保证二叉搜索树的性质不变。返回二叉搜索树(有可能被更新)的根节点的引用。一般来说,删除节点可分为两个步骤:首先找到需要删除的节点;如果找到了,删除它。 示例1: 输入:root=[5,3,6,2,4,nu......