China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-03 13:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help]Stupid girl can't figure out the problem, batch processing xml files View 1,401 Replies 13
Original Poster Posted 2007-02-16 11:17 ·  中国 上海 电信
初级用户
Credits 147
Posts 20
Joined 2003-01-11 00:00
23-year member
UID 725
Gender Female
Status Offline
Want to make a batch processing to replace a certain character in the xml file,

The code in the xml file:


……

……

……

grid_menu_bg="xin003.jpg"/>

……

……

……

Want to add code idle_status_area_bg="spacer.png" idle_softkey_area_bg="spacer.png"/> after grid_menu_bg="xin003.jpg"

That is, the code after batch processing is:



grid_menu_bg="xin003.jpg" idle_status_area_bg="spacer.png" idle_softkey_area_bg="spacer.png"/>


Ah: change:
grid_menu_bg="xin003.jpg"/> to grid_menu_bg="xin003.jpg" idle_status_area_bg="spacer.png" idle_softkey_area_bg="spacer.png"/>


But the xin003 in xin003.jpg in the code is random,


Hehe, I know it's very difficult~~~~~
Floor 2 Posted 2007-02-16 22:29 ·  中国 浙江 台州 温岭市 电信
高级用户
★★
DOS学徒
Credits 526
Posts 252
Joined 2007-02-12 05:35
19-year member
UID 79286
Gender Male
Status Offline
Don't know but still topped it
Floor 3 Posted 2007-02-16 22:48 ·  美国 缅因州
中级用户
★★
Credits 316
Posts 152
Joined 2006-06-18 13:01
20-year member
UID 57204
Gender Male
Status Offline
Please provide the XML code you want to translate.
Floor 4 Posted 2007-02-17 00:47 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Is there a line with this grid_menu_bg?
Floor 5 Posted 2007-02-17 02:53 ·  中国 黑龙江 哈尔滨 电信
高级用户
★★★
Credits 760
Posts 357
Joined 2005-10-10 22:33
20-year member
UID 43332
Status Offline
@echo off
:00
SET string=grid_menu_bg
strings new_string=READ new_string.TXT,1
SET file_name=xml
SET new_file=new_file.TXT
SET take_string_count=1,25
SET line_number=1
:11
SET X=>NUL
strings x=read %file_name%,%line_number%
if "x"=="" goto exit
strings line_number=add %line_number%,1
ECHO %X%|FIND /I "%string%">NUL
if ERRORLEVEL 1 goto write_old_file
:write_new_file
STRINGS X=MID %X%,%take_string_count%
ECHO %X%%new_string%>>%new_file%
GOTO 11
:write_old_file
ECHO %X%>>%new_file%
GOTO 11
:exit
for %%x in (X string new_string file_name new_file take_string_count line_number) do SET %%x=>NUL
CLS
ECHO The work has been completed, please check!

[ Last edited by 0451lym on 2007-2-17 at 08:06 AM ]
Floor 6 Posted 2007-02-17 07:04 ·  中国 广西 南宁 中移铁通
初级用户
Credits 147
Posts 20
Joined 2003-01-11 00:00
23-year member
UID 725
Gender Female
Status Offline
The code in the file has no pattern. The constants that appear are the same, but the values are different.

The code of the abc..xml file is as follows (a code for making themes for mobile phones. The file names of the pictures are random and do not need to be modified. Just modify some parts and add some code, that is, add in the code of the red part):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE theme PUBLIC "-//NOKIA//DTD THEME 2.0//EN" "theme.dtd">
<theme name="chun1" version="2.0">
<colors
display="main"
status_area_font_color="0x0"
calendar_highlight_color="0xccffcc" />
<wallpaper
main_display_graphics="026.jpg" />
<screensaver
main_display_graphics="025.jpg" />
<background
main_default_bg="xin003.jpg"
grid_menu_bg="xin003.jpg" />
<calendar_bg
january="xin003.jpg"
february="xin003.jpg"
march="xin003.jpg"
april="xin003.jpg"
may="xin003.jpg"
june="xin003.jpg"
july="xin003.jpg"
august="xin003.jpg"
september="xin003.jpg"
october="xin003.jpg"
november="xin003.jpg"
december="xin003.jpg" />
<highlight
list="32.png" />
<startup
main_display_graphics="026.jpg" />
<shutdown
main_display_graphics="026.jpg" />
<transformation_open
main_display_graphics="026.jpg" />
<transformation_close
main_display_graphics="026.jpg" />
</theme>



Change grid_menu_bg="xin003.jpg" /> to grid_menu_bg="xin003.jpg" idle_status_area_bg="spacer.png" idle_softkey_area_bg="spacer.png" />

Note: The black part is the code to be added,

Among them, "xin003.jpg" after grid_menu_bg= may be "xin066.jpg" or "xin055.jpg" or other image format files, no need to change~~~
Floor 7 Posted 2007-02-17 07:37 ·  中国 黑龙江 哈尔滨 电信
高级用户
★★★
Credits 760
Posts 357
Joined 2005-10-10 22:33
20-year member
UID 43332
Status Offline
Oh, so confusing, you still haven't figured out something so simple? It's already written perfectly for you. Just change the beginning.

SET 字符串=grid_menu_bg
strings 新字符串=READ 新字符串.TXT,1
SET 文件名=xml
SET 新文件=新文件.TXT
SET 取字符串数=1,25
SET 行数=1

-----------------------------------------------------------
Create a new file named "新字符串.TXT" and write the following inside:
idle_status_area_bg="spacer.png" idle_softkey_area_bg="spacer.png" />

[ Last edited by 0451lym on 2007-2-17 at 08:07 AM ]
Floor 8 Posted 2007-02-17 08:02 ·  中国 黑龙江 哈尔滨 电信
高级用户
★★★
Credits 760
Posts 357
Joined 2005-10-10 22:33
20-year member
UID 43332
Status Offline
Explain the meaning of batch processing!
The blue part is the translation.


@echo off
:00
REM Set the content to be found as a variable, take its most unique string, not necessarily the whole
SET 字符串=grid_menu_bg
REM Set the string to be added as a variable, need to write the complete string in new string.TXT first
strings 新字符串=READ 新字符串.TXT,1
REM Set the file to be modified as a variable
SET 文件名=xml
REM Set the modified file as a variable
SET 新文件=新文件.TXT
REM The string content to be intercepted and retained in the original file
SET 取字符串数=1,25
REM Set the starting line number of the original file to 1
SET 行数=1
:11
REM Clear variable X
SET X=>NUL
REM Read a line of the original file and set it as variable X
strings x=read %文件名%,行数
REM If read is the last line, then exit
if "x"=="" goto 退出
REM Set the line number to add 1, that is, determine the next line to read next time
strings 行数=add %行数%,1
REM Check if there is a line with the string that needs to be modified in variable X
ECHO %X%|FIND /I "%字符串%">NUL
REM If not, then jump to the mark of writing the old file
if ERRORLEVEL 1 goto 写旧文件
:写新文件
REM There is a line in X with the string that needs to be modified, get the part of the string to be retained
STRINGS X=MID %X%,%取字符串数%
REM Write the retained string part and the part of the string to be added into the new file
ECHO %X%%新字符串%>>%新文件%
GOTO 11
:写旧文件
REM Write the old file line that does not need to be modified into the new file
ECHO %X%>>%新文件%
GOTO 11
:退出
REM Clear all variables
for %%x in (X 字符串 新字符串 文件名 新文件 取字符串数 行数) do SET %%x=>NUL
CLS
ECHO Work has been completed, please accept!

[ Last edited by 0451lym on 2007-2-17 at 08:05 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
fastslz +3 2007-02-20 09:28
Floor 9 Posted 2007-02-17 08:49 ·  中国 上海 电信
新手上路
Credits 12
Posts 6
Joined 2007-02-17 07:59
19-year member
UID 79683
Gender Male
Status Offline
Yeah? I don't know anything at all. It's my first post, and I'm starting to learn.
Floor 10 Posted 2007-02-17 14:00 ·  中国 广西 南宁 中移铁通
初级用户
Credits 147
Posts 20
Joined 2003-01-11 00:00
23-year member
UID 725
Gender Female
Status Offline
5555 5555 5555 :(:( 0451lym Uncle, something's wrong~~~

Entered an infinite loop, and the content of the newly created file.TXT is:
ECHO is in a closed state.
ECHO is in a closed state.
ECHO is in a closed state.
ECHO is in a closed state.
……

The attached file below is that file. Please trouble the master to test it~~~~ I'm stupid~~~~ Thanks a lot~~~~ :( :(

[ Last edited by 米娜 on 2007-2-17 at 04:23 PM ]
Attachments
theme_descriptor.rar (528 bytes, Credits to download 1 pts, Downloads: 5)
Floor 11 Posted 2007-02-18 07:13 ·  中国 四川 成都 电信
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Silly girl can't think of a problem Series theme~~~~

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 12 Posted 2007-02-19 15:45 ·  中国 广西 玉林 中移铁通
初级用户
Credits 147
Posts 20
Joined 2003-01-11 00:00
23-year member
UID 725
Gender Female
Status Offline
Floor 13 Posted 2007-02-23 01:40 ·  中国 宁夏 银川 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
sed -r "/^[ ]*grid_menu_bg=\x22xin([0-9]{3})\.jpg\x22[ ]*\/>[ ]*$/!d;s/\/>/idle_status_area_bg=\x22spacer.png\x22 idle_softkey_area_bg=\x22spacer.png\x22 &/" life

Only suitable for this
Floor 14 Posted 2007-02-23 08:28 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
If using a third party, it is recommended to use UE to edit. Using regular expressions is very fast...
Forum Jump: