用于提取特定XML标记的值的批处理文件 [英] A batch file to extract the value of a specific XML tag

查看:146
本文介绍了用于提取特定XML标记的值的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

* *我需要一个批处理文件,仅检索 Data 标签值(不带标签名称),并将其写入.txt文件。

**I need a batch file that retrieves the Data tag value only (without the tag name) and writes it down into a .txt file. This file might have more XML tags than those listed.

因此输出应为:

资本收益是美国收入差距的关键因素 - 赢家背后的力量全部是我们经济体系的咒语。 **

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.**

我的档案看起来像这样:**

My file looks like this :**

<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的优秀工具:

I don't have a windows machine, so forgive if the syntax is a little off, but something like this may help, if the data is as you listed in your example, though you may want to consider using Powershell, as it has excellent tools for dealing with 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"


$ b b

如果您需要帮助,请告诉我。我不得不在环境中工作,其中DOS是他们会让我们使用,所以我感到你的痛苦。祝你好运! :)

Let me know if you need help. I have had to work in environments, where DOS was all they would let us use, so I feel your pain. Good luck! :)

这篇关于用于提取特定XML标记的值的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆