2

これを行う方法が見つかりません (StackOverflow を検索してみました)。

フォーマット済みの xml ファイルがあり、そこからブロックをそのまま (フォーマット、タブ、<、> などを変更せずに) 抽出する必要があります。たとえば、次のようなファイルがあるとします。some.xml

ブロックは次のように区切られています。

 <!- Let us call this tag_begin -->
 <Ask Ref_Ask="XXXYYYYY">   
   ...
 <!- Let us call this tag_end -->
 </Ask>  

blockend タグの開始行と終了行を抽出することに成功しましたが、result.txt ファイルにすべての行の長さを含めることができません: 行は 127 文字の長さで停止します: 何が問題なのですか?

@echo off

Set Tag_Begin="<Ask Ref_Ask="
Set Tag_End="</Ask>"
set NB=XXXYYYY
set /A CPTE=0
set Line_Begin=
set Line_End=


Rem --- Find all possible start of block lines, and extract the good one set to Line_Begin
findstr /n /C:%Tag_Begin% some.xml | find /i "%NB%"> temporary.txt
for /f "tokens=1 delims=:" %%L in (temporary.txt) do set Line_Begin=%%L

Rem --- Finding the line order (from all possible start lines) which match the good one
findstr /n /C:%Tag_Begin% some.xml | findstr /n "%NB%"> temporary.txt
for /f "tokens=1 delims=:" %%O in (temporary.txt) do set order_begin=%%O
set /A order_begin-=1


Rem -- Looking for all possible end of block lines, and extract the "order_begin" one for Line_End
for /f "skip=%order_begin% tokens=1 delims=:" %%F in ('findstr /n /C:%Tag_End% some.xml') do set Line_End=%%F & goto away
:away


setlocal enabledelayedexpansion
for /f %%L in (some.xml) do (
set /A CPTE+=1
echo CPTE=!CPTE!
if !CPTE! GEQ %Line_Begin% if !CPTE! LEQ %Line_End% echo %%L >> result.txt
)
setlocal disabledelayedexpansion

del temporary.txt
4

2 に答える 2

0

これは、 http://www.dostips.com/forum/viewtopic.php?f=findrepl.bat 3&t=4697から呼び出されるヘルパー バッチ ファイルを使用します。

findrepl.batバッチファイルと同じフォルダに配置します。

@echo off
type some.xml|findrepl "<Ask Ref_Ask=.XXXYYYYY.>" /e:"</Ask>" >newfile.xml
于 2013-10-18T08:16:09.720 に答える
0

未検証:

        @echo off
        for /f "tokens=1 delims=:" %%L in ('findstr /n "<!- Let us call this begin tag -->" ssome.xml') do ( 
         set begin_line=%%L
        )

        for /f "tokens=1 delims=:" %%L in ('findstr /n "<!- Let us call this end tag -->" some.xml') do ( 
         set /a end_line=%%L+1
        )

        echo showing lines between %end_line% and %begin_line%
        break>"%temp%\empty"
        fc "%temp%\empty" "some.xml" /lb  %end_line% /t |more +4 | findstr /B /E /V "*****" | more +%begin_line%
        del /Q /F "%temp%\empty"

ファイルで 3 か所を変更しsome.xmlます。

于 2013-10-16T14:33:04.383 に答える