**我需要一个批处理文件来检索Data仅标记值(不带标记名称)并将其写入 .txt 文件。该文件可能具有比列出的更多的 XML 标签。
所以输出应该是:
资本收益是美国收入差距的关键因素,而胜利者背后的力量是我们经济体系的全部准则。如果您想平衡在美国的盈利能力,则必须提高 15% 的资本利得税。**
我的文件如下所示:**
<TABLE>
Table 30
<ROW>
Multiple Rows
<DATA>
Capital gains are the key ingredient of income disparity in the US-- and the force
behind the winner takes all mantra of our economic system. If you want even out
earning power in the U.S, you have to raise the 15% capital gains tax.
</DATA>
</ROW>
</TABLE>
我没有 Windows 机器,所以如果语法有点偏离,请原谅,但是如果数据如您在示例中列出的那样,这样的东西可能会有所帮助,尽管您可能需要考虑使用 Powershell,因为它具有出色的功能处理 XML 的工具:
setlocal enabledelayedexpansion
set start_reading="0"
set stop_reading="0"
set your_file_name=%~1
if EXIST "%your_file_name%.txt" del "%your_file_name%.txt"
for /f "eol=; tokens=1 delims=" %%c in ('type "%your_file_name_here%.xml"') do (
set line=%%c
@REM Determine if at start of Data Tag
for /f "eol=; tokens=1 delims=" %%d in ('echo !line! ^| findstr /i /c:"<DATA>"') do (
set start_reading="1"
)
@REM Determine if at end of Data Tag
for /f "eol=; tokens=1 delims=" %%d in ('echo !line! ^| findstr /i /c:"</DATA>"') do (
set stop_reading="1"
)
@REM stop reading DATA tag input
if "!stop_reading!"=="1" (
set start_reading="0"
)
@REM skips first line assumed to be <DATA>
if "!start_reading!"=="2" (
echo !line! >> "%your_file_name_here%.txt"
)
@REM Ready to start reading post <DATA> line
if "!start_reading!"=="1" (
set stop_reading="0"
set start_reading="2"
)
)
@REM Check results
type "%your_file_name_here%.txt"
如果您需要帮助,请告诉我。我不得不在只允许我们使用 DOS 的环境中工作,所以我能理解你的痛苦。祝你好运! :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)