[英]Read a single file containing multiple XML line code blocks into multiple xml files in Talend
[英]read xml tag from a file containing single line in bat file
我必須從xml文件中讀取特定標簽,該文件的全部內容都在一行中。 例如,我的employee.xml文件將如下所示
<EMP><FNAME>ss</FNAME><LNAME>rr</LNAME><ID>11</ID></EMP>
我想在.bat文件中讀取LNAME的值。
如果所有標記都位於單獨的行中,則我能夠讀取文件,但是如果它們位於同一行,則我的代碼將失敗。
任何人都可以幫助解決這個問題嗎? 還可以在同一批處理文件中處理這兩種情況嗎?
這使用了一個名為repl
.bat的幫助程序批處理文件,該文件來自repl
: //www.dostips.com/forum/viewtopic.php? repl
3855
將repl.bat
與批處理文件放在同一文件夾中。
@echo off
for /f "delims=" %%a in ('type employee.xml ^|repl ".*<LNAME>(.*)</LNAME>.*" "$1" a ') do echo "%%a"
pause
@ECHO OFF
SETLOCAL
FOR /f "delims=" %%i IN (q19138159.txt) DO SET line=%%i
:loop
FOR /f "tokens=1*delims=<>" %%i IN ("%line%") DO SET line=%%j&IF /i NOT "%%i"=="lname" GOTO loop
FOR /f "tokens=1delims=<>" %%i IN ("%line%") DO SET line=%%i
ECHO lname=%line%=
GOTO :EOF
其中q19138159.txt是包含您的XML行的文件。
對於大文件-在SED的支持下
@ECHO OFF
SETLOCAL
FOR /f "delims=" %%i IN (
'sed s#.*\x3cLName\x3e\(.*\^)\x3c/LName\x3e.*#\1# q19138159.txt'
) DO ECHO %%i
GOTO :eof
GNUSED
將處理包含<LName>something or other</LName>
以提取something or other
。
處理命令是
s substitute # a delimiter .* Any number of any characters \x3c \( sed instruction : save... .* any number of any characters \^) End of thing-to-be-saved; `)` escaped by `^` to not-close the `IN` \x3c .* any number of any characters # delimiter between substitute-for-string and substitute-with string \1 retrieve thing #1 saved # end of substitute-with string
Google for GNUSED
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.