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

[已解决]20元修改归类并正则匹配所有属性值

具体报酬:20元人民币
支付方式:支付宝,微信转账
联系方式:QQ296578353
有效期限:问题解决之前。还有可能没发现的问题,可能调试时才发现 如果有报酬会提升
例句
<Image x="#sw/2+#offset_x" y="#sh-360+#offset_y" align="center" alignV="center" pivotX="87" pivotY="87"   rotation="#angle+#angle2" srcExp="'unlock'+#Color_id+'.webp" visibility="!(#charge.visibility)-#music.visibility*#Gb"/>
<Image x="#sw/2" y="#sh-360" align="center" alignV="center" srcExp="'style'+#Color_id+'.webp" visibility="!(#charge.visibility)-#music.visibility*#Gb"/>

<Circle name="wave_2_show" x="#sw/2" y="#sh-360" align="center" alignV="center" r="66" strokeColor="@Color" weight="7" visibility="1-#music.visibility*#Gb">
<Circle name="wave_3_show" x="#sw/2" y="#sh-360" align="center" alignV="center" r="77" strokeColor="@Color" weight="7" visibility="1-#music.visibility*#Gb">
生成
<Var name="Image_x共2个" type="number[] const="false" values="#sw/2+#offset_x,#sw/2"/> #数字数组用,隔开
<Var name="Image_y共2个" type="number[] const="false" values="#sh-360+#offset_y,#sh-360"/>
... #以此类推归类并正则匹配所有属性值 统计数量依据节点数即<Image <Circle 节点(标签)的对应数量 并非值的数量
<Var name="Image_visibility共2个" type="number[] const="false" values="!(#charge.visibility)-#music.visibility*#Gb,!(#charge.visibility)-#music.visibility*#Gb"/>

<Var name="Circle_name共2个" type="string[]" const="true" expression="''''" values="'wave_2_show','wave_3_show'"/>#字符数组以','隔开 name align alignV strokeColor package class 为字符数组(可能还有)其它为数字数组
<Var name="Circle_x共2个" type="number[] const="false" values="#sw/2,#sw/2"/>
<Var name="Circle_y共2个" type="number[] const="false" values="#sh-360,#sh-360"/>
...

以下是大神回帖我照葫芦画瓢改的,比较固定、针对,不够灵活 没有统计和归类
  1. $f =gc manifest.xml -readcount 0 -enc utf8;
  2. $x =[regex]::matches($f,'(?is)(?<=\bx=")[^"]+\b').value;
  3. $y =[regex]::Matches($f,'(?is)(?<=\by=")[^"]+\b').value;
  4. $w =[regex]::matches($f,'(?is)(?<=\bw=")[^"]+\b').value;
  5. $h =[regex]::matches($f,'(?!s)(?<=\bh=")[^"]+\b').value;
  6. $r =[regex]::matches($f,'(?!s)(?<=\br=")[^"]+\b').value;
  7. $alpha =[regex]::matches($f,'(?is)(?<=\balpha=")[^"]+\b').value;
  8. $pivotX =[regex]::matches($f,'(?is)(?<=\bpivotX=")[^"]+\b').value;
  9. $pivotY =[regex]::matches($f,'(?is)(?<=\bpivotY=")[^"]+\b').value;
  10. $angle =[regex]::matches($f,'(?is)(?<=\bangle=")[^"]+\b').value;
  11. $scale =[regex]::matches($f,'(?is)(?<=\bscale=")[^"]+\b').value;
  12. $src =[regex]::matches($f,'(?is)(?<=\bsrc=")[^"]+\b').value;
  13. $srcExp =[regex]::matches($f,'(?is)(?<=\bsrcExp=")[^"]+\b').value;
  14. $align =[regex]::matches($f,'(?is)(?<=\balign=")[^"]+\b').value;
  15. $alignV =[regex]::matches($f,'(?is)(?<=\balignV=")[^"]+\b').value;
  16. $package =[regex]::matches($f,'(?is)(?<=\bpackage=")[^"]+\b').value;
  17. $class =[regex]::matches($f,'(?is)(?<=\bclass=")[^"]+\b').value;
  18. $out ='<Var name="信息_x" type="number[] const="false" values="'+($x -join ',')+'"/>'+"`r`n"+'<Var name="信息_y" type="number[] const="false" values="'+($y -join ',')+'"/>'+"`r`n"+'<Var name="信息_w" type="number[] const="true" values="'+($w -join ',')+'"/>'+"`r`n"+'<Var name="信息_h" type="number[] const="true" values="'+($h -join ',')+'"/>'+"`r`n"+'<Var name="信息_r" type="number[] const="true" values="'+($r -join ',')+'"/>'+"`r`n"+'<Var name="信息_alpha" type="number[] const="true" values="'+($alpha -join ',')+'"/>'+"`r`n"+'<Var name="信息_pivotX" type="number[] const="true" values="'+($pivotX -join ',')+'"/>'+"`r`n"+'<Var name="信息_pivotY" type="number[] const="true" values="'+($pivotY -join ',')+'"/>'+"`r`n"+'<Var name="信息_angle" type="number[] const="true" values="'+($angle -join ',')+'"/>'+"`r`n"+'<Var name="信息_scale" type="number[] const="true" values="'+($scale -join ',')+'"/>'+"`r`n"+'<Var name="信息_src" type="string[]" const="true" expression="''''" values="'''+($src -join ''',''')+'''"/>'+"`r`n"+'<Var name="信息_srcExp" type="string[]" const="true" expression="''''" values="'''+($srcExp -join ''',''')+'''"/>'+"`r`n"+'<Var name="信息_align" type="string[]" const="true" expression="''''" values="'''+($align -join ''',''')+'''"/>'+"`r`n"+'<Var name="信息_alignV" type="string[]" const="true" expression="''''" values="'''+($alignV -join ''',''')+'''"/>'+"`r`n"+'<Var name="信息_package" type="string[]" const="true" expression="''''" values="'''+($package -Join ''',''')+'''"/>'+"`r`n"+'<Var name="信息_class" type="string[]" const="true" expression="''''" values="'''+($class -join ''',''')+'''"/>'
  19. sc '.\数组信息.xml' -value $out  -enc utf8 -force;
复制代码

本帖最后由 smss 于 2019-7-28 11:31 编辑

回复 9# smss 可以加个补全的功能吗

例如 <Image srcExp="'Ai/icon_'+#__i+'.webp"/>
没有x y值 赋值 x=0 y=0  主要用来参考相对位置 (否则电脑代入数组时会代入后边有值的其他图片)


<Var name="Image_x共1个" type="number[]" const="false" values="0
<Var name="Image_y共1个" type="number[]" const="false" values="0

以下节点需要这样做 最好设个变量 方便添加  
<Group <Text <Array <Button <DateTime <Circle <Image

TOP

回复 8# flashercs 小小心意略表寸心

TOP

回复 7# smss
微信
微信:flashercs
QQ:49908356

TOP

本帖最后由 smss 于 2019-7-27 21:58 编辑

回复 6# flashercs
可以给个支付宝/微信 略表谢意吗

TOP

回复 5# smss


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

TOP

回复 4# flashercs
链接: https://pan.baidu.com/s/1Lpy_Br2DIDX3gKhUhMk8MA 提取码: qrf5

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

回复 2# flashercs
没有获取到Image_y的值 真是奇怪 其它正常
  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[0] | Get-Member -MemberType Properties).Name | 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
复制代码

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

返回列表