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

TOP

回复 5# smss


    楼上改了 你试试
微信:flashercs
QQ:49908356

TOP

本帖最后由 flashercs 于 2019-7-27 20:56 编辑

回复 3# smss
  1. # xml源文件
  2. $xmlfile = 'manifest.xml'
  3. # xml输出文件
  4. $outfile = '数组信息.xml'
  5. # attribute类型为number
  6. $数字数组 = 'x', 'y', 'w', 'h', 'pivotX', 'pivotY', 'rotation', 'visibility', 'size'
  7. # attribute类型为string
  8. $字符数组 = 'name', 'src', 'srcExp', 'align', 'alignV', 'text', 'textExp', 'color', 'fillColor', 'strokeColor', 'package', 'class'
  9. $strxml = Get-Content -ReadCount 0 -LiteralPath $xmlfile -Encoding UTF8 -Raw
  10. $rexmlnode = [regex]'<[^>]+>'
  11. $rexmlnodename = [regex]'(?<=<)\w+'
  12. $rexmlattribute = [regex]'\w+="[^"]*"'
  13. (
  14.   ($rexmlnode.Matches($strxml) | ForEach-Object -Begin { Write-Host 'Matching XML node elements...begin' -ForegroundColor Green } -End { Write-Host 'Matching XML node elements...end' -ForegroundColor Green } -Process {
  15.       $strnode = $_.Value
  16.       # $strnodename=$rexmlnodename.Match($strnode).Value
  17.       invoke-expression "[pscustomobject]@{__nodeName__=`"$($rexmlnodename.Match($strnode).Value)`";$($rexmlattribute.Matches($strnode).Value -join ';')}"
  18.     } ) | Group-Object -Property '__nodeName__' | ForEach-Object -Begin { Write-Host 'Grouping XML node elements...begin' -ForegroundColor Green } -End { Write-Host 'Grouping XML node elements...end' -ForegroundColor Green } -Process {
  19.     $groupName = $_.Name
  20.     # $groupCount = $_.Group.Count
  21.     foreach ($attributeName in (($_.Group | ForEach-Object { Get-Member -InputObject $_ -MemberType Properties }).Name | Select-Object -Unique | Where-Object { $_ -ne '__nodeName__' })) {
  22.       $attributes = $_.Group.$attributeName | Where-Object { $null -ne $_ }
  23.       if ($attributeName -in $字符数组) {
  24.         "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"string[]`" const=`"true`" expression=`"''`" values=`"$($attributes -replace '(?s)^.*$',"'$&'" -join ',')`"/>"
  25.       }
  26.       elseif ($attributename -in $数字数组) {
  27.         "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"number[]`" const=`"false`" values=`"$($attributes -join ',')`"/>"
  28.       }
  29.     }
  30.   }) | Set-Content -LiteralPath $outfile -Encoding UTF8
复制代码
微信:flashercs
QQ:49908356

TOP

本帖最后由 flashercs 于 2019-7-27 19:21 编辑
  1. # xml源文件
  2. $xmlfile = 'C:\test\1.xml'
  3. # xml输出文件
  4. $outfile = 'C:\test\1_out.xml'
  5. # attribute类型为string
  6. $typestring = 'name', 'srcExp', 'src', 'align', 'alignV', 'strokeColor', 'package', 'class'
  7. # attribute类型为number
  8. $typenumber = 'x', 'y', 'pivotX', 'pivotY', 'rotation', 'visibility'
  9. $strxml = Get-Content -ReadCount 0 -LiteralPath $xmlfile -Encoding UTF8 -Raw
  10. $rexmlnode = [regex]'<[^>]+>'
  11. $rexmlnodename = [regex]'(?<=<)\w+'
  12. $rexmlattribute = [regex]'\w+="[^"]*"'
  13. (
  14.   ($rexmlnode.Matches($strxml) | ForEach-Object -Begin { Write-Host 'Matching XML node elements...begin' -ForegroundColor Green } -End { Write-Host 'Matching XML node elements...end' -ForegroundColor Green } -Process {
  15.       $strnode = $_.Value
  16.       # $strnodename=$rexmlnodename.Match($strnode).Value
  17.       invoke-expression "[pscustomobject]@{__nodeName__=`"$($rexmlnodename.Match($strnode).Value)`";$($rexmlattribute.Matches($strnode).Value -join ';')}"
  18.     } ) | Group-Object -Property '__nodeName__' | ForEach-Object -Begin { Write-Host 'Grouping XML node elements...begin' -ForegroundColor Green } -End { Write-Host 'Grouping XML node elements...end' -ForegroundColor Green } -Process {
  19.     $groupName = $_.Name
  20.     # $groupCount = $_.Group.Count
  21.     foreach ($attributeName in (($_.Group[0] | Get-Member -MemberType Properties).Name | Where-Object { $_ -ne '__nodeName__' })) {
  22.       $attributes = $_.Group.$attributeName | Where-Object { $null -ne $_ }
  23.       if ($attributeName -in $typestring) {
  24.         "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"string[]`" const=`"true`" expression=`"''`" values=`"$($attributes -replace '(?s)^.*$',"'$&'" -join ',')`"/>"
  25.       }
  26.       elseif ($attributename -in $typenumber) {
  27.         "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"number[]`" const=`"false`" values=`"$($attributes -join ',')`"/>"
  28.       }
  29.     }
  30.   }) | Set-Content -LiteralPath $outfile -Encoding UTF8
复制代码
微信:flashercs
QQ:49908356

TOP

返回列表