我正在尝试插入800个唯一的< REMARK>这是一个评论< / REMARK>将元素转换为现有的800个XML文件集.我只用< REMARK>生成了800个文档.我希望将元素插入到每个XML中.我想,我可以根据共享文件名将此元素插入到相应的XML文档中.例如,我在一个文件夹中有一个名为WNYC-SCHK-2004-02-20-37540.xml的XML,其中只包含此信息< REMARK>想想西班牙古典音乐,Manuel de Falla的名字自然会浮现在脑海中. < / REMARK>我想将元素插入到< CHANGETIME>正下方名为WNYC-SCHK-2004-02-20-37540.xml的文件中.元素如下:
<?xml version="1.0" encoding="ISO-8859-1"?> <ENTRIES> <ENTRY> <NUMBER>622</NUMBER> <CLASS>Audio</CLASS> <TITLE>WNYC-SCHK-2004-02-20-37540</TITLE> <GENERATOR>DBM</GENERATOR> <CREATOR>JPASSMOR</CREATOR> <DATE>2015-01-06</DATE> <DATUM>2015-01-06</DATUM> <TIME>11:48:59</TIME> <TIMESTAMP>2015-01-06 11:48:59</TIMESTAMP> <LENGTH>00:58:53.920</LENGTH> <DURATION>3533920</DURATION> <SOFTDELETED>0</SOFTDELETED> <NODELETE>0</NODELETE> <READY>0</READY> <PERFECT>0</PERFECT> <FORARCHIVE>0</FORARCHIVE> <ARCHIVING>0</ARCHIVING> <ARCHIVED>0</ARCHIVED> <GROWING>0</GROWING> <NEW>0</NEW> <INVALID>0</INVALID> <LOWRESEXISTS>0</LOWRESEXISTS> <KEYFRAMEEXISTS>0</KEYFRAMEEXISTS> <VSAT>0</VSAT> <LOOP>0</LOOP> <INVISIBLE>0</INVISIBLE> <SHAREDAUdio>0</SHAREDAUdio> <TRANSMITTED>0</TRANSMITTED> <ROYALTIES>0</ROYALTIES> <WITHTEXTFILE>0</WITHTEXTFILE> <INDEXED>0</INDEXED> <PERSONALRAdio>0</PERSONALRAdio> <REQUESTDEARCHIVE>0</REQUESTDEARCHIVE> <REPLFLAGS>0</REPLFLAGS> <STATE>Existing</STATE> <AUTHOR>ARCHIVES</AUTHOR> <EDITOR>JPASSMOR</EDITOR> <CHANGEUSER>JPASSMOR</CHANGEUSER> <CHANGEDATE>2015-01-26</CHANGEDATE> <CHANGETIME>09:33:07</CHANGETIME> <FILESIZE>628255824</FILESIZE> <AUdioFORMAT>Wave,BWF,RIFF</AUdioFORMAT> <AUdioMODE>Stereo</AUdioMODE> <SAMPLERATE>44100</SAMPLERATE> <BITRATE>0</BITRATE> <TEXTLENGTH>00:00:00.000</TEXTLENGTH> <TEXTDURATION>0</TEXTDURATION> <BROADCASTINGS>0</BROADCASTINGS> <MARKIN>00:00:00.000</MARKIN> <MARKOUT>00:58:53.920</MARKOUT> </ENTRY> </ENTRIES>
所以它看起来像这样
<?xml version="1.0" encoding="ISO-8859-1"?> <ENTRIES> <ENTRY> <NUMBER>622</NUMBER> <CLASS>Audio</CLASS> <TITLE>WNYC-SCHK-2004-02-20-37540</TITLE> <GENERATOR>DBM</GENERATOR> <CREATOR>JPASSMOR</CREATOR> <DATE>2015-01-06</DATE> <DATUM>2015-01-06</DATUM> <TIME>11:48:59</TIME> <TIMESTAMP>2015-01-06 11:48:59</TIMESTAMP> <LENGTH>00:58:53.920</LENGTH> <DURATION>3533920</DURATION> <SOFTDELETED>0</SOFTDELETED> <NODELETE>0</NODELETE> <READY>0</READY> <PERFECT>0</PERFECT> <FORARCHIVE>0</FORARCHIVE> <ARCHIVING>0</ARCHIVING> <ARCHIVED>0</ARCHIVED> <GROWING>0</GROWING> <NEW>0</NEW> <INVALID>0</INVALID> <LOWRESEXISTS>0</LOWRESEXISTS> <KEYFRAMEEXISTS>0</KEYFRAMEEXISTS> <VSAT>0</VSAT> <LOOP>0</LOOP> <INVISIBLE>0</INVISIBLE> <SHAREDAUdio>0</SHAREDAUdio> <TRANSMITTED>0</TRANSMITTED> <ROYALTIES>0</ROYALTIES> <WITHTEXTFILE>0</WITHTEXTFILE> <INDEXED>0</INDEXED> <PERSONALRAdio>0</PERSONALRAdio> <REQUESTDEARCHIVE>0</REQUESTDEARCHIVE> <REPLFLAGS>0</REPLFLAGS> <STATE>Existing</STATE> <AUTHOR>ARCHIVES</AUTHOR> <EDITOR>JPASSMOR</EDITOR> <CHANGEUSER>JPASSMOR</CHANGEUSER> <CHANGEDATE>2015-01-26</CHANGEDATE> <CHANGETIME>09:33:07</CHANGETIME> <REMARK>Think of Spanish classical music and the name Manuel de Falla naturally comes to mind.</REMARK> <FILESIZE>628255824</FILESIZE> <AUdioFORMAT>Wave,RIFF</AUdioFORMAT> <AUdioMODE>Stereo</AUdioMODE> <SAMPLERATE>44100</SAMPLERATE> <BITRATE>0</BITRATE> <TEXTLENGTH>00:00:00.000</TEXTLENGTH> <TEXTDURATION>0</TEXTDURATION> <BROADCASTINGS>0</BROADCASTINGS> <MARKIN>00:00:00.000</MARKIN> <MARKOUT>00:58:53.920</MARKOUT> </ENTRY> </ENTRIES>
我认为可能有一种方法可以使用xsl根据批处理中的共享文件名将备注从一个xml doc复制到另一个xml doc.或者可能有更简单的方法吗?
这个问题有一个有趣的方面,所以我用它来测试一个不同的方法来处理文件.
@echo off setlocal EnableDelayedExpansion rem Process all .xml files in current directory for %%a in (*.xml) do ( rem Locate the line numbers where "CHANGETIME" and "/ENTRIES" appears set "insertLine=" for /F "delims=:" %%b in ('findstr /N "CHANGETIME /ENTRIES" "%%a"') do ( if not defined insertLine ( set "insertLine=%%b" ) else ( set "lastLine=%%b" ) ) rem Block used to read-input-file/create-output-file < "%%a" ( rem Read the first line from input file set /P "line=" rem Copy lines up to the insertion point for /L %%i in (1,1,!insertLine!) do set /P "line=!line!" & echo/ rem Insert the corresponding REMARK file type "RemarksFolder\%%a" rem Copy the rest of lines set /A insertLine+=1 for /L %%i in (!insertLine!,!lastLine!) do set /P "line=!line!" & echo/ ) > "output.tmp" rem Block-end rem Replace input file with created output file move /Y "output.tmp" "%%a" > NUL )
该程序应该比逐行比较的其他方法运行得更快;然而,它的缺点是从所有线上移除了前导空间.虽然可以插入额外的代码来解决这一问题,但这样做会减慢进程…