中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-03 14:02
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » [Help]Stupid girl can't figure out the problem, batch processing xml files
Printable Version  1,403 / 13
Floor1 米娜 Posted 2007-02-16 11:17
初级用户 Posts 20 Credits 147
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~~~~~
Floor2 gne3 Posted 2007-02-16 22:29
高级用户 Posts 252 Credits 526
Don't know but still topped it
Floor3 amao Posted 2007-02-16 22:48
中级用户 Posts 152 Credits 316
Please provide the XML code you want to translate.
Floor4 slore Posted 2007-02-17 00:47
铂金会员 Posts 2,478 Credits 5,212
Is there a line with this grid_menu_bg?
Floor5 0451lym Posted 2007-02-17 02:53
高级用户 Posts 357 Credits 760
@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 ]
Floor6 米娜 Posted 2007-02-17 07:04
初级用户 Posts 20 Credits 147
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~~~
Floor7 0451lym Posted 2007-02-17 07:37
高级用户 Posts 357 Credits 760
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 ]
Floor8 0451lym Posted 2007-02-17 08:02
高级用户 Posts 357 Credits 760
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 ]
Floor9 grizzlyjian Posted 2007-02-17 08:49
新手上路 Posts 6 Credits 12
Yeah? I don't know anything at all. It's my first post, and I'm starting to learn.
Floor10 米娜 Posted 2007-02-17 14:00
初级用户 Posts 20 Credits 147
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)
Floor11 electronixtar Posted 2007-02-18 07:13
铂金会员 Posts 2,672 Credits 7,493
Silly girl can't think of a problem Series theme~~~~
Floor12 米娜 Posted 2007-02-19 15:45
初级用户 Posts 20 Credits 147
Floor13 vkill Posted 2007-02-23 01:40
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
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
Floor14 slore Posted 2007-02-23 08:28
铂金会员 Posts 2,478 Credits 5,212
If using a third party, it is recommended to use UE to edit. Using regular expressions is very fast...
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023