[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 如何查找并替换xml文本中含有指定节点/元素/标记/标签的特定行里的部分字符串/内容

如何搜索文本中指定范围内容并替换
搜索目录下 config.xml 文件内容 并提取红字部分 <location>D:\OneDrive\MouseRecorder\Phraseexpress\phrases.pxp</location>然后把文本内所有的"D:\OneDrive\MouseRecorder\Phraseexpress\"替换为当前 config.xml 文件当前路径
替换的同时还要保持其他行的内容不变,比如说204,205,206这几行,比较特殊。


内容如下
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xml>
  3. <pexconfig>
  4. <PhraseFile>
  5. <Data>
  6. <phrases>
  7. <min_ver>10.0.34</min_ver>
  8. <version>4.0.21</version>
  9. <lastused>
  10. <description>最后使用</description>
  11. <location>D:\OneDrive\MouseRecorder\Phraseexpress\lastused.pxp</location>
  12. <cacheloaded>False</cacheloaded>
  13. </lastused>
  14. <clipboard>
  15. <description>剪贴板缓存</description>
  16. <location>D:\OneDrive\MouseRecorder\Phraseexpress\clipboard.pxp</location>
  17. <cacheloaded>False</cacheloaded>
  18. </clipboard>
  19. <file>
  20. <description>快捷用语</description>
  21. <location>D:\OneDrive\MouseRecorder\Phraseexpress\phrases.pxp</location>
  22. <cacheloaded>False</cacheloaded>
  23. </file>
  24. </phrases>
  25. </Data>
  26. <NP/>
  27. <DoSyncFiles>-1</DoSyncFiles>
  28. <PhrasesTouched>1</PhrasesTouched>
  29. <ServerSwitched>0</ServerSwitched>
  30. <DBT/>
  31. <DBTS/>
  32. <BackupCount>10</BackupCount>
  33. <BackupPath>D:\OneDrive\MouseRecorder\Phraseexpress\</BackupPath>
  34. <CacheSQLData>0</CacheSQLData>
  35. <LastSaveTarget/>
  36. <SaveHistoryPaths/>
  37. </PhraseFile>
  38. <Other>
  39. <DateOfFirstUse10>42741,5829091898</DateOfFirstUse10>
  40. <DateOfFirstUseHash10>BC05A0AB89AABB7FC82FD4250520C1D0</DateOfFirstUseHash10>
  41. <PayOff>49,95</PayOff>
  42. <PaidOff>0</PaidOff>
  43. <Version>10.5.41</Version>
  44. <IsPro>1</IsPro>
  45. <IsOlPro>0</IsOlPro>
  46. <Rdata10>44485233516735306658773041513D3D</Rdata10>
  47. <RdataX10/>
  48. <Commercial>0</Commercial>
  49. <IsLocalPro>1</IsLocalPro>
  50. </Other>
  51. <AutoLearn>
  52. <Active>0</Active>
  53. <BigSentence>1</BigSentence>
  54. <SmallSentence>1</SmallSentence>
  55. <NumberSentence>0</NumberSentence>
  56. <SpecSentence>0</SpecSentence>
  57. <InsideWords>1</InsideWords>
  58. <Precision>1</Precision>
  59. <MaxSuggestCount>200</MaxSuggestCount>
  60. <WordsVsSentences>2</WordsVsSentences>
  61. <UsageVsLength>4</UsageVsLength>
  62. <MaxLife>14</MaxLife>
  63. <MaxSize>100000</MaxSize>
  64. <DoNumbers>1</DoNumbers>
  65. <IgnoreList/>
  66. <SingleBlockList/>
  67. <CompareDate>42785,2943869907</CompareDate>
  68. <AutoPrecision>1</AutoPrecision>
  69. <SingleContext>1</SingleContext>
  70. <SuggestionLength>15</SuggestionLength>
  71. <WordSuggestionLength>5</WordSuggestionLength>
  72. <AllowedApps/>
  73. <DeclinedApps/>
  74. <PartExec>0</PartExec>
  75. <BigPartExec>0</BigPartExec>
  76. </AutoLearn>
  77. <General>
  78. <PopupDisplayMode>2</PopupDisplayMode>
  79. <PopupPositionMode>0</PopupPositionMode>
  80. <PopupFixedPositionX>0</PopupFixedPositionX>
  81. <PopupFixedPositionY>0</PopupFixedPositionY>
  82. <PopupMaxItems>0</PopupMaxItems>
  83. <ClipCacheHK>3158</ClipCacheHK>
  84. <LastUsedHK>0</LastUsedHK>
  85. <AutoCorrectHK>0</AutoCorrectHK>
  86. <SimpleMode>0</SimpleMode>
  87. <AutoSkip>0</AutoSkip>
  88. <DoStats>0</DoStats>
  89. <LocalOnly>1</LocalOnly>
  90. <IgnoreCaps>0</IgnoreCaps>
  91. <DoSound0>0</DoSound0>
  92. <SoundFile0/>
  93. <DoSound1>0</DoSound1>
  94. <SoundFile1/>
  95. <DoSound2>0</DoSound2>
  96. <SoundFile2/>
  97. <DoSound3>0</DoSound3>
  98. <SoundFile3/>
  99. <DoSound4>0</DoSound4>
  100. <SoundFile4/>
  101. <NewPhraseShortcut>1603</NewPhraseShortcut>
  102. <LastUsedShortcut>1605</LastUsedShortcut>
  103. <OpenSetShortcut>3151</OpenSetShortcut>
  104. <EnDisAppShortcut>3194</EnDisAppShortcut>
  105. <TrayPopupShortcut>0</TrayPopupShortcut>
  106. <QuickSearchShortcut>114</QuickSearchShortcut>
  107. <CheckUpdates>0</CheckUpdates>
  108. <NextUpdate>42748,9159329977</NextUpdate>
  109. <SkipUpdateVer>0</SkipUpdateVer>
  110. <ListenUDPPort>1036</ListenUDPPort>
  111. <ServerUDPPort>1037</ServerUDPPort>
  112. <DoProxy>2</DoProxy>
  113. <ProxyServer/>
  114. <ProxyPort>80</ProxyPort>
  115. <ProxyUsername/>
  116. <ProxyPassword/>
  117. <LicenseServer/>
  118. <SQLLicenseDatabase/>
  119. <ExecKey>9</ExecKey>
  120. <PopupModifier>0</PopupModifier>
  121. <PopupShortcutType>1</PopupShortcutType>
  122. <PopupSearchCount2>3</PopupSearchCount2>
  123. <PopupSearchInline>1</PopupSearchInline>
  124. <PopupSearchInlineExt>1</PopupSearchInlineExt>
  125. <PopupSearchCase>0</PopupSearchCase>
  126. <PopupSearchRecurse>1</PopupSearchRecurse>
  127. <PopupSearchMenuText>1</PopupSearchMenuText>
  128. <PopupSearchExtended>1</PopupSearchExtended>
  129. </General>
  130. <ClipCache>
  131. <PlainOnly>1</PlainOnly>
  132. <TrimSpaces>0</TrimSpaces>
  133. </ClipCache>
  134. <AutoCorrect>
  135. <MinLength>4</MinLength>
  136. <MinCount>3</MinCount>
  137. </AutoCorrect>
  138. <LastText>
  139. <MinLength>10</MinLength>
  140. </LastText>
  141. <Dialogs>
  142. <ShowInsertDlg>0</ShowInsertDlg>
  143. <ShowDeleteDlg>1</ShowDeleteDlg>
  144. <ShowDatalossDlg>1</ShowDatalossDlg>
  145. <ShowMacroErrorDlg>1</ShowMacroErrorDlg>
  146. <ShowExpertDlg>0</ShowExpertDlg>
  147. <ShowHotkeyCheckDlg>1</ShowHotkeyCheckDlg>
  148. <ShowCharsNullDlg>1</ShowCharsNullDlg>
  149. <ShowExtendedConfirmation>1</ShowExtendedConfirmation>
  150. <ShowFunDlg>1</ShowFunDlg>
  151. <ShowAppPhrase>1</ShowAppPhrase>
  152. <ShowDetailsDlg>1</ShowDetailsDlg>
  153. <ShowBadAutotextDlg>1</ShowBadAutotextDlg>
  154. <ShowUpdateDialog>1</ShowUpdateDialog>
  155. <ShowOptsChangeDlg>1</ShowOptsChangeDlg>
  156. <ShowUSBDlg>0</ShowUSBDlg>
  157. <ShowNoneDelimDlg>1</ShowNoneDelimDlg>
  158. <ShowSearchInserts>1</ShowSearchInserts>
  159. <ShowAsianCheck>1</ShowAsianCheck>
  160. <ServerFoundCheck>1</ServerFoundCheck>
  161. <ShowMultiEditDlg>1</ShowMultiEditDlg>
  162. <FirstStart>0</FirstStart>
  163. <ShowAllAppDlg>1</ShowAllAppDlg>
  164. <ShowToolCloseDlg>0</ShowToolCloseDlg>
  165. <ShowExportPassDlg>1</ShowExportPassDlg>
  166. <ShowDropBoxFilesDlg>0</ShowDropBoxFilesDlg>
  167. <ShowOpenDlg>1</ShowOpenDlg>
  168. <ShowUpgExpireDlg>1</ShowUpgExpireDlg>
  169. <ShowLicExpireDlg>1</ShowLicExpireDlg>
  170. <ShowSavePosDlg>1</ShowSavePosDlg>
  171. <ShowIcompatDlg>1</ShowIcompatDlg>
  172. <ShowCancelDlg>1</ShowCancelDlg>
  173. <ShowDelimBalloon>1</ShowDelimBalloon>
  174. <ShowDDDlg>1</ShowDDDlg>
  175. <ShowPhraseWiz>1</ShowPhraseWiz>
  176. <ShowLastUsedBubble>1</ShowLastUsedBubble>
  177. <ShowElevatedBubble>1</ShowElevatedBubble>
  178. <NoWarnings>0</NoWarnings>
  179. <MinOnClose>1</MinOnClose>
  180. <CancelOnEscape>1</CancelOnEscape>
  181. <DoImportWizard>0</DoImportWizard>
  182. <Language>0</Language>
  183. <FindDlgWidth>483</FindDlgWidth>
  184. <FindDlgHeight>277</FindDlgHeight>
  185. <InputDlgLeft>-2147483648</InputDlgLeft>
  186. <InputDlgTop>-2147483648</InputDlgTop>
  187. <FormularLeft>-2147483648</FormularLeft>
  188. <FormularTop>-2147483648</FormularTop>
  189. <InputOnTop>1</InputOnTop>
  190. <FormOnTop>1</FormOnTop>
  191. <ShowBubbles>0</ShowBubbles>
  192. <LastOpenDlgRes>0</LastOpenDlgRes>
  193. <CaretPositionMode>4</CaretPositionMode>
  194. <CaretPositionX>-99999999</CaretPositionX>
  195. <CaretPositionY>0</CaretPositionY>
  196. <PrintPreviewWidth>0</PrintPreviewWidth>
  197. <PrintPreviewHeight>0</PrintPreviewHeight>
  198. <SearchHistory>FEJ0LlFZNAASPwEpL1VHEVxPGXx0OAU/CSY+SRoHIAYmDWRRFgUPYicJWlQ0NAI=</SearchHistory>
  199. </Dialogs>
  200. <Expert>
  201. <AllowedApps/>
  202. <DeclinedApps/>
  203. <AppMethods/>
  204. <CharsBefore>#0#10#9#13 "'&lt;{([/\-_</CharsBefore>
  205. <CharsAfter>#9#10#13 "'&gt;}]).,?!/\:;-_ </CharsAfter>
  206. <SentenceDelimiters>.;!?#9#13#10</SentenceDelimiters>
  207. <GlobalPrefix/>
  208. <MaxCharsAfterPopupEx>0</MaxCharsAfterPopupEx>
  209. <PopupHideTime>3600</PopupHideTime>
  210. <RndDelay>0</RndDelay>
  211. <HotkeyCheck>1</HotkeyCheck>
  212. <MaxDescLength>128</MaxDescLength>
  213. <ClipboardBackup>1</ClipboardBackup>
  214. <ForceFocus>1</ForceFocus>
  215. <UseOldParser>0</UseOldParser>
  216. <SaveMeta>1</SaveMeta>
  217. <UseClbFrom>0</UseClbFrom>
  218. <FocusDelay>200</FocusDelay>
  219. <RestoreClbDelay>350</RestoreClbDelay>
  220. <PlainClbDelay2>50</PlainClbDelay2>
  221. <SimKeyDelay>90</SimKeyDelay>
  222. <GlobalTiming>750</GlobalTiming>
  223. <DoRouteEnter>0</DoRouteEnter>
  224. <WatchClipboard>0</WatchClipboard>
  225. <MinRefineLength>3</MinRefineLength>
  226. <KeyByKeyPasteMethod>0</KeyByKeyPasteMethod>
  227. <UTFMail>0</UTFMail>
  228. <MailMode>1</MailMode>
  229. <maxUnwantedChars>10</maxUnwantedChars>
  230. <DoACC>0</DoACC>
  231. <AutoCapsCount>2</AutoCapsCount>
  232. <DoAutoCaps>0</DoAutoCaps>
  233. <DocGenSeparator/>
  234. </Expert>
  235. <Popup>
  236. <VistaStyle>1</VistaStyle>
  237. <AutolearnColor>-16777212</AutolearnColor>
  238. <AutolearnTextColor>-16777209</AutolearnTextColor>
  239. <SelRectColor>14314496</SelRectColor>
  240. <SelBackColor>16045234</SelBackColor>
  241. <BackColor>15790320</BackColor>
  242. <SeparatorColor>12632256</SeparatorColor>
  243. <BorderColor>8421504</BorderColor>
  244. <SearchColor>-16777211</SearchColor>
  245. <QsColor>2322898</QsColor>
  246. <PopupBackgroundColor>-16777212</PopupBackgroundColor>
  247. <PopupHighlightColor>-16777187</PopupHighlightColor>
  248. <PopupAutotextBackgroundColor>-16777212</PopupAutotextBackgroundColor>
  249. <PopupAutotextHighlightColor>-16777187</PopupAutotextHighlightColor>
  250. <PopupHotkeyBackgroundColor>-16777212</PopupHotkeyBackgroundColor>
  251. <PopupHotkeyHighlightColor>-16777187</PopupHotkeyHighlightColor>
  252. <PopupHotBackgroundColor>-16777212</PopupHotBackgroundColor>
  253. <PopupHotHighlightColor>-16777187</PopupHotHighlightColor>
  254. <PopupTextColor>-16777209</PopupTextColor>
  255. <PopupTextColorSelected>-16777209</PopupTextColorSelected>
  256. <PopupAutoTextColor>-16777209</PopupAutoTextColor>
  257. <PopupAutoTextColorSelected>-16777209</PopupAutoTextColorSelected>
  258. <PopupHotkeyTextColor>-16777209</PopupHotkeyTextColor>
  259. <PopupHotkeyTextColorSelected>-16777209</PopupHotkeyTextColorSelected>
  260. <PopupHotTextColor>-16777209</PopupHotTextColor>
  261. <PopupHotTextColorSelected>-16777209</PopupHotTextColorSelected>
  262. <PopupDelay>200</PopupDelay>
  263. <HintDelay>200</HintDelay>
  264. <MaxCaptionLength>96</MaxCaptionLength>
  265. <PopupHintLength>1024</PopupHintLength>
  266. <PopupShowHint>1</PopupShowHint>
  267. <ShowInfo>0</ShowInfo>
  268. <FilterTray>1</FilterTray>
  269. <SortPopupMode>0</SortPopupMode>
  270. <SortPopupCol>0</SortPopupCol>
  271. <SortPopupDir>0</SortPopupDir>
  272. <AlPopupShowDelay>200</AlPopupShowDelay>
  273. <PopupFont>Microsoft YaHei UI|9|000</PopupFont>
  274. </Popup>
  275. <Edit>
  276. <OldPlainView>0</OldPlainView>
  277. <DoWrap>1</DoWrap>
  278. <DoGutter>0</DoGutter>
  279. <DoSyn>1</DoSyn>
  280. <DoRulers>0</DoRulers>
  281. <DoShowSpecialChars>0</DoShowSpecialChars>
  282. <OleFitMode>0</OleFitMode>
  283. <LastFormat>0</LastFormat>
  284. <LastDDAct>-1</LastDDAct>
  285. <DoLastUsedFormat>0</DoLastUsedFormat>
  286. <ShowDetails>1</ShowDetails>
  287. <LastNewPhraseFocus>0</LastNewPhraseFocus>
  288. </Edit>
  289. <MainWindow>
  290. <Left>2039</Left>
  291. <Top>89</Top>
  292. <Width>940</Width>
  293. <Height>725</Height>
  294. <MainSplitter>34,0425531914894</MainSplitter>
  295. <TreeSplitter>0</TreeSplitter>
  296. <MainSplitterWidth>320</MainSplitterWidth>
  297. <TreeSplitterWidth>320</TreeSplitterWidth>
  298. <Maximized>0</Maximized>
  299. </MainWindow>
  300. <UI>
  301. <PhraseColVis0>1</PhraseColVis0>
  302. <PhraseColWidth0>80</PhraseColWidth0>
  303. <PhraseColPos0>0</PhraseColPos0>
  304. <PhraseColVis1>1</PhraseColVis1>
  305. <PhraseColWidth1>68</PhraseColWidth1>
  306. <PhraseColPos1>1</PhraseColPos1>
  307. <PhraseColVis2>1</PhraseColVis2>
  308. <PhraseColWidth2>80</PhraseColWidth2>
  309. <PhraseColPos2>2</PhraseColPos2>
  310. <PhraseColVis3>1</PhraseColVis3>
  311. <PhraseColWidth3>80</PhraseColWidth3>
  312. <PhraseColPos3>3</PhraseColPos3>
  313. <PhraseColVis4>1</PhraseColVis4>
  314. <PhraseColWidth4>80</PhraseColWidth4>
  315. <PhraseColPos4>4</PhraseColPos4>
  316. <PhraseColVis5>1</PhraseColVis5>
  317. <LockWidth1>0</LockWidth1>
  318. <LockWidth2>0</LockWidth2>
  319. <LockWidth3>0</LockWidth3>
  320. <TreeViewMode>0</TreeViewMode>
  321. <HideDemoFunctions>0</HideDemoFunctions>
  322. <PlainFontSize>10</PlainFontSize>
  323. <MakroOwnFormat>1</MakroOwnFormat>
  324. <AccessRightsByOwnerOnly>0</AccessRightsByOwnerOnly>
  325. <HideUsers>0</HideUsers>
  326. </UI>
  327. <Search>
  328. <MinCharSearch>1</MinCharSearch>
  329. <SearchThresold>100</SearchThresold>
  330. <SearchWhere>1000</SearchWhere>
  331. <SearchCase>0</SearchCase>
  332. <SearchWhole>0</SearchWhole>
  333. <SearchExact>0</SearchExact>
  334. </Search>
  335. <Statistics>
  336. <StatsDate>42785,5212947801</StatsDate>
  337. <TodayPhrases>0</TodayPhrases>
  338. <TotalPhrases9>0</TotalPhrases9>
  339. <TodayChars>0</TodayChars>
  340. <TotalChars>0</TotalChars>
  341. <UserSpeed>120</UserSpeed>
  342. <UserLoan>10</UserLoan>
  343. <Measured>0</Measured>
  344. </Statistics>
  345. <Hidden>
  346. <DoNewBitmap>1</DoNewBitmap>
  347. <MSAutoCorrectDisabled>0</MSAutoCorrectDisabled>
  348. <oldVersion>0</oldVersion>
  349. <SaveDictionary>1</SaveDictionary>
  350. </Hidden>
  351. <Network>
  352. <ConnectTimeout>1000</ConnectTimeout>
  353. <ReadTimeout>30000</ReadTimeout>
  354. <WaitTimeout>1500</WaitTimeout>
  355. <RetryRegister>5000</RetryRegister>
  356. <RetryConnect>2000</RetryConnect>
  357. <RetryPass>500</RetryPass>
  358. <RetryPassCancel>5000</RetryPassCancel>
  359. <SuspendTimeout>1500</SuspendTimeout>
  360. <UdpTimeout>1500</UdpTimeout>
  361. <WaitThreadsTerminate>1</WaitThreadsTerminate>
  362. <SQLPingInterval>10000</SQLPingInterval>
  363. <SQLLoginTimeout>10</SQLLoginTimeout>
  364. </Network>
  365. <Server>
  366. <UserData/>
  367. </Server>
  368. </pexconfig>
  369. </xml>
复制代码
1

评分人数

    • pcl_test: 优先文字说明,少发图片PB -4

回复 1# hmlstfqtl


    PowerShell代碼
  1. dir  config.xml | %{
  2. [xml]$xml = gc  -Literal $_.FullName -enc UTF8
  3. $a = $_.DirectoryName
  4. select-xml  "//location" $xml | %{
  5. $_.node."#text" =  "$(Join-Path  $a 'phrases.pxp')"
  6. }
  7. $xml.save($a + '\config-New.xml' )
  8. }
复制代码

TOP

可以单纯用批处理实现吗   因为目标的电脑不能执行powershell脚本

TOP

返回列表