标题: [文件操作] 【已解决】求助批处理把单个XML重新梳理内容格式到CSV中 [打印本页]
作者: zhengwei007 时间: 2024-3-20 00:57 标题: 【已解决】求助批处理把单个XML重新梳理内容格式到CSV中
本帖最后由 zhengwei007 于 2024-3-20 11:07 编辑
这个文件a.xml中,有几千行以下内容的代码,我取其中之一,如下:- <?xml version="1.0" encoding="UTF-8"?>
- <list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/augmentation_retailchances.xsd">
- <weapon type="warrior">
- <stone id="8723">
- <variation id="1">
- <category probability="100">
- <augment id="1" chance="1.1" />
- <augment id="2" chance="1.1" />
- <augment id="3" chance="1.1" />
- <augment id="4" chance="1.1" />
- <augment id="5" chance="1.1" />
- <augment id="6" chance="1.1" />
- <augment id="7" chance="1.1" />
- <augment id="8" chance="1.1" />
- <augment id="9" chance="1.1" />
- <augment id="10" chance="1.1" />
- </category>
- </variation>
- <variation id="2">
- <category probability="55">
- <augment id="7281" chance="7.69" />
- <augment id="7282" chance="7.69" />
- <augment id="7283" chance="7.69" />
- <augment id="7284" chance="7.69" />
- <augment id="7285" chance="7.69" />
- <augment id="7286" chance="7.69" />
- <augment id="7287" chance="7.69" />
- <augment id="7288" chance="7.69" />
- <augment id="7289" chance="7.69" />
- <augment id="7290" chance="7.69" />
- <augment id="7291" chance="7.69" />
- <augment id="7292" chance="7.69" />
- <augment id="7293" chance="7.72" />
- </category>
- <category probability="35">
- <augment id="8191" chance="5.88" />
- <augment id="8192" chance="5.88" />
- <augment id="8193" chance="5.88" />
- <augment id="8194" chance="5.88" />
- <augment id="8195" chance="5.88" />
- <augment id="8196" chance="5.88" />
- <augment id="8197" chance="5.88" />
- <augment id="8198" chance="5.88" />
- <augment id="8199" chance="5.88" />
- <augment id="8200" chance="5.88" />
- <augment id="8201" chance="5.88" />
- <augment id="8202" chance="5.88" />
- <augment id="8203" chance="5.88" />
- <augment id="8204" chance="5.88" />
- <augment id="8205" chance="5.88" />
- <augment id="8206" chance="5.88" />
- <augment id="8207" chance="5.92" />
- </category>
- <category probability="7">
- <augment id="14578" chance="0.93" />
- <augment id="14579" chance="0.93" />
- <augment id="14580" chance="0.93" />
- <augment id="14581" chance="0.93" />
- <augment id="14582" chance="0.93" />
- <augment id="14583" chance="0.93" />
- <augment id="14584" chance="0.93" />
- <augment id="14585" chance="0.93" />
- <augment id="14586" chance="0.93" />
- <augment id="14587" chance="0.93" />
- <augment id="14588" chance="0.93" />
- </category>
- <category probability="3">
- <augment id="14685" chance="1.85" />
- <augment id="14686" chance="1.85" />
- <augment id="14687" chance="1.85" />
- <augment id="14688" chance="1.85" />
- <augment id="14689" chance="1.85" />
- <augment id="14690" chance="1.85" />
- <augment id="14691" chance="1.85" />
- <augment id="14692" chance="1.85" />
- <augment id="14693" chance="1.85" />
- <augment id="14694" chance="1.85" />
- <augment id="14695" chance="1.85" />
- </category>
- </variation>
- </stone>
复制代码
我希望通过批处理能整理成以下内容,标题我自己写,直接输出到sour.csv中即可- stone id variation id category probability augment id
- 8723 1 100 1
- 8723 1 100 2
- 8723 1 100 3
- 8723 1 100 4
- 8723 1 100 5
- 8723 1 100 6
- 8723 1 100 7
- 8723 1 100 8
- 8723 1 100 9
- 8723 1 100 10
- 8723 2 55 7281
- 8723 2 55 7282
- 8723 2 55 7283
- 8723 2 55 7284
- 8723 2 55 7285
- 8723 2 55 7286
- 8723 2 55 7287
- 8723 2 55 7288
- 8723 2 55 7289
- 8723 2 55 7290
- 8723 2 55 7291
- 8723 2 55 7292
- 8723 2 55 7293
- 8723 2 35 8191
- 8723 2 35 8192
- 8723 2 35 8193
- 8723 2 35 8194
- 8723 2 35 8195
- 8723 2 35 8196
- 8723 2 35 8197
- 8723 2 35 8198
- 8723 2 35 8199
- 8723 2 35 8200
- 8723 2 35 8201
- 8723 2 35 8202
- 8723 2 35 8203
- 8723 2 35 8204
- 8723 2 35 8205
- 8723 2 35 8206
- 8723 2 35 8207
- 8723 2 7 14578
- 8723 2 7 14579
- 8723 2 7 14580
- 8723 2 7 14581
- 8723 2 7 14582
- 8723 2 7 14583
- 8723 2 7 14584
- 8723 2 7 14585
- 8723 2 7 14586
- 8723 2 7 14587
- 8723 2 7 14588
- 8723 2 3 14685
- 8723 2 3 14686
- 8723 2 3 14687
- 8723 2 3 14688
- 8723 2 3 14689
- 8723 2 3 14690
- 8723 2 3 14691
- 8723 2 3 14692
- 8723 2 3 14693
- 8723 2 3 14694
- 8723 2 3 14695
复制代码
作者: wanghan519 时间: 2024-3-20 05:36
第三方xmlstarlet,在bat大概是- xml sel -t -m "//augment" -v "ancestor::stone/@id" -o " " -v "ancestor::variation/@id" -o " " -v "../@probability" -o " " -v "./@id" -n a.xml
复制代码
第三方awk在busybox里大概是- awk -v RS='<|>' -F '"' '/^stone /{s=$2;next}/^variation /{v=$2;next}/^category /{c=$2;next}/^augment /{print s,v,c,$2}' a.xml
复制代码
作者: qixiaobin0715 时间: 2024-3-20 08:55
- @echo off
- setlocal enabledelayedexpansion
- for /f "tokens=1,3 delims=<>= " %%i in (a.xml) do (
- if "%%i"=="stone" (
- set s1=%%~j
- ) else if /i "%%i"=="variation" (
- set s2=%%~j
- ) else if /i "%%i"=="category" (
- set s3=%%~j
- ) else if /i "%%i"=="augment" (
- echo,!s1! !s2! !s3! %%~j
- )
- )
- pause
复制代码
作者: zhengwei007 时间: 2024-3-20 11:07
谢谢楼上两位大佬, 已搞定。
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |