使用批处理提取XML文件中的ProductKey并过滤左右两边字符

您可以使用批处理中的字符串处理命令来过滤掉左右两边的字符。以下是一个示例批处理代码:

@echo off
setlocal enabledelayedexpansion

set "xmlContent=<?xml version='1.0' encoding='utf-8'?><Key xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><ProductKey>HNKC4-XWCBB-D4GMP-D3PP3-8K9CT</ProductKey><ProductKeyID>3556107027678</ProductKeyID><ProductKeyState>2</ProductKeyState><ProductKeyPartNumber /></Key>" 

rem 提取ProductKey的值
for /f "tokens=2 delims=<>" %%a in ('echo %xmlContent% ^| findstr /c:"ProductKey"') do (
    set "productKey=%%a"
)

rem 过滤掉左右两边的字符
set "filteredKey=!productKey:~1,-1!"

 echo %filteredKey%

您需要将%xmlContent%替换为您要处理的XML文件内容。运行上述代码后,它将提取XML中的ProductKey值,并过滤掉左右的字符,然后将结果打印出来。在上述示例中,过滤后的结果将为HNKC4-XWCBB-D4GMP-D3PP3-8K9CT


原文地址: https://www.cveoy.top/t/topic/pk0a 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录