xml - 通过搜索 id 使用批处理脚本删除 xml 标记的文本数据中的一大块行
问题描述
我想通过匹配 id 来删除 XML 标记的完整部分:
<?xml version="1.0"?>
<messages>
<note ID="501">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note ID="502">
<to>Jani</to>
<from>Tove</from>
<heading>Re: Reminder</heading>
<body>I will not!</body>
</note>
我的批处理代码是:
@ECHO OFF
title Delete Data
echo Press the id that needs to be Deleted
set /p id=
echo hi
set notepad_program=C:\Windows\System32\notepad.exe
set notepad_file=C:\Users\shubham1.mishra\Desktop\Employee
cd "%notepad_file%"
rem for /F "tokens=*" %%A in (Edit_sample_xml.txt) do
rem if %%A equ "502" (type Edit_sample_xml.txt | findstr /v %id% > Xml2.txt %%A)
type Edit_sample_xml.txt | findstr /v %id% > Xml2.txt
start "%notepad_program%" "Xml2.txt"
pause
出口
我的代码只删除了与 id 匹配的一行,但我想删除完整的块,即具有该特定 id 的所有数据的完整“note”标签。
解决方案
推荐阅读
- mysql - LinkTable 在 MS Access 中不可编辑
- kubernetes - 最新的 Kubernetes 版本引发 RBAC 错误
- javascript - Vue.js:带有来自 API 调用的数组的 addRoutes 方法
- video-capture - 从 pcap rtp capture 获取 h.265 视频文件
- android - 导航组件,添加或替换片段或其他东西,如隐藏显示片段
- regex - sed 替换依赖于环境
- c# - 使用 Moq 模拟被测试对象的依赖项时出现类型错误
- sql - 根据时间间隔划分时段
- winforms - webRequest API 的第二次代理验证失败
- php - Laravel 应用程序执行两个请求,但第二个不需要