标题: [已解决]20元修改归类并正则匹配所有属性值 [打印本页]
作者: smss 时间: 2019-7-27 15:23 标题: [已解决]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"/>
...
以下是大神回帖我照葫芦画瓢改的,比较固定、针对,不够灵活 没有统计和归类- $f =gc manifest.xml -readcount 0 -enc utf8;
- $x =[regex]::matches($f,'(?is)(?<=\bx=")[^"]+\b').value;
- $y =[regex]::Matches($f,'(?is)(?<=\by=")[^"]+\b').value;
- $w =[regex]::matches($f,'(?is)(?<=\bw=")[^"]+\b').value;
- $h =[regex]::matches($f,'(?!s)(?<=\bh=")[^"]+\b').value;
- $r =[regex]::matches($f,'(?!s)(?<=\br=")[^"]+\b').value;
- $alpha =[regex]::matches($f,'(?is)(?<=\balpha=")[^"]+\b').value;
- $pivotX =[regex]::matches($f,'(?is)(?<=\bpivotX=")[^"]+\b').value;
- $pivotY =[regex]::matches($f,'(?is)(?<=\bpivotY=")[^"]+\b').value;
- $angle =[regex]::matches($f,'(?is)(?<=\bangle=")[^"]+\b').value;
- $scale =[regex]::matches($f,'(?is)(?<=\bscale=")[^"]+\b').value;
- $src =[regex]::matches($f,'(?is)(?<=\bsrc=")[^"]+\b').value;
- $srcExp =[regex]::matches($f,'(?is)(?<=\bsrcExp=")[^"]+\b').value;
- $align =[regex]::matches($f,'(?is)(?<=\balign=")[^"]+\b').value;
- $alignV =[regex]::matches($f,'(?is)(?<=\balignV=")[^"]+\b').value;
- $package =[regex]::matches($f,'(?is)(?<=\bpackage=")[^"]+\b').value;
- $class =[regex]::matches($f,'(?is)(?<=\bclass=")[^"]+\b').value;
- $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 ''',''')+'''"/>'
- sc '.\数组信息.xml' -value $out -enc utf8 -force;
复制代码
作者: flashercs 时间: 2019-7-27 18:58
本帖最后由 flashercs 于 2019-7-27 19:21 编辑
- # xml源文件
- $xmlfile = 'C:\test\1.xml'
- # xml输出文件
- $outfile = 'C:\test\1_out.xml'
- # attribute类型为string
- $typestring = 'name', 'srcExp', 'src', 'align', 'alignV', 'strokeColor', 'package', 'class'
- # attribute类型为number
- $typenumber = 'x', 'y', 'pivotX', 'pivotY', 'rotation', 'visibility'
-
- $strxml = Get-Content -ReadCount 0 -LiteralPath $xmlfile -Encoding UTF8 -Raw
- $rexmlnode = [regex]'<[^>]+>'
- $rexmlnodename = [regex]'(?<=<)\w+'
- $rexmlattribute = [regex]'\w+="[^"]*"'
- (
- ($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 {
- $strnode = $_.Value
- # $strnodename=$rexmlnodename.Match($strnode).Value
- invoke-expression "[pscustomobject]@{__nodeName__=`"$($rexmlnodename.Match($strnode).Value)`";$($rexmlattribute.Matches($strnode).Value -join ';')}"
- } ) | 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 {
- $groupName = $_.Name
- # $groupCount = $_.Group.Count
- foreach ($attributeName in (($_.Group[0] | Get-Member -MemberType Properties).Name | Where-Object { $_ -ne '__nodeName__' })) {
- $attributes = $_.Group.$attributeName | Where-Object { $null -ne $_ }
- if ($attributeName -in $typestring) {
- "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"string[]`" const=`"true`" expression=`"''`" values=`"$($attributes -replace '(?s)^.*$',"'$&'" -join ',')`"/>"
- }
- elseif ($attributename -in $typenumber) {
- "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"number[]`" const=`"false`" values=`"$($attributes -join ',')`"/>"
- }
- }
- }) | Set-Content -LiteralPath $outfile -Encoding UTF8
复制代码
作者: smss 时间: 2019-7-27 20:25
回复 2# flashercs
没有获取到Image_y的值 真是奇怪 其它正常
- # xml源文件
- $xmlfile = 'manifest.xml'
- # xml输出文件
- $outfile = '数组信息.xml'
- # attribute类型为number
- $数字数组 = 'x', 'y', 'w', 'h', 'pivotX', 'pivotY', 'rotation', 'visibility', 'size'
-
- # attribute类型为string
- $字符数组 = 'name', 'src', 'srcExp', 'align', 'alignV', 'text', 'textExp', 'color', 'fillColor', 'strokeColor', 'package', 'class'
-
- $strxml = Get-Content -ReadCount 0 -LiteralPath $xmlfile -Encoding UTF8 -Raw
- $rexmlnode = [regex]'<[^>]+>'
- $rexmlnodename = [regex]'(?<=<)\w+'
- $rexmlattribute = [regex]'\w+="[^"]*"'
- (
- ($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 {
- $strnode = $_.Value
- # $strnodename=$rexmlnodename.Match($strnode).Value
- invoke-expression "[pscustomobject]@{__nodeName__=`"$($rexmlnodename.Match($strnode).Value)`";$($rexmlattribute.Matches($strnode).Value -join ';')}"
- } ) | 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 {
- $groupName = $_.Name
- # $groupCount = $_.Group.Count
- foreach ($attributeName in (($_.Group[0] | Get-Member -MemberType Properties).Name | Where-Object { $_ -ne '__nodeName__' })) {
- $attributes = $_.Group.$attributeName | Where-Object { $null -ne $_ }
- if ($attributeName -in $字符数组) {
- "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"string[]`" const=`"true`" expression=`"''`" values=`"$($attributes -replace '(?s)^.*$',"'$&'" -join ',')`"/>"
- }
- elseif ($attributename -in $数字数组) {
- "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"number[]`" const=`"false`" values=`"$($attributes -join ',')`"/>"
- }
- }
- }) | Set-Content -LiteralPath $outfile -Encoding UTF8
复制代码
作者: flashercs 时间: 2019-7-27 20:31
本帖最后由 flashercs 于 2019-7-27 20:56 编辑
回复 3# smss - # xml源文件
- $xmlfile = 'manifest.xml'
- # xml输出文件
- $outfile = '数组信息.xml'
- # attribute类型为number
- $数字数组 = 'x', 'y', 'w', 'h', 'pivotX', 'pivotY', 'rotation', 'visibility', 'size'
-
- # attribute类型为string
- $字符数组 = 'name', 'src', 'srcExp', 'align', 'alignV', 'text', 'textExp', 'color', 'fillColor', 'strokeColor', 'package', 'class'
-
- $strxml = Get-Content -ReadCount 0 -LiteralPath $xmlfile -Encoding UTF8 -Raw
- $rexmlnode = [regex]'<[^>]+>'
- $rexmlnodename = [regex]'(?<=<)\w+'
- $rexmlattribute = [regex]'\w+="[^"]*"'
- (
- ($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 {
- $strnode = $_.Value
- # $strnodename=$rexmlnodename.Match($strnode).Value
- invoke-expression "[pscustomobject]@{__nodeName__=`"$($rexmlnodename.Match($strnode).Value)`";$($rexmlattribute.Matches($strnode).Value -join ';')}"
- } ) | 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 {
- $groupName = $_.Name
- # $groupCount = $_.Group.Count
- foreach ($attributeName in (($_.Group | ForEach-Object { Get-Member -InputObject $_ -MemberType Properties }).Name | Select-Object -Unique | Where-Object { $_ -ne '__nodeName__' })) {
- $attributes = $_.Group.$attributeName | Where-Object { $null -ne $_ }
- if ($attributeName -in $字符数组) {
- "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"string[]`" const=`"true`" expression=`"''`" values=`"$($attributes -replace '(?s)^.*$',"'$&'" -join ',')`"/>"
- }
- elseif ($attributename -in $数字数组) {
- "<Var name=`"${groupName}_${attributename}共$($attributes.Count)个`" type=`"number[]`" const=`"false`" values=`"$($attributes -join ',')`"/>"
- }
- }
- }) | Set-Content -LiteralPath $outfile -Encoding UTF8
复制代码
作者: smss 时间: 2019-7-27 20:55
回复 4# flashercs
链接: https://pan.baidu.com/s/1Lpy_Br2DIDX3gKhUhMk8MA 提取码: qrf5
作者: flashercs 时间: 2019-7-27 21:38
回复 5# smss
楼上改了 你试试
作者: smss 时间: 2019-7-27 21:54
本帖最后由 smss 于 2019-7-27 21:58 编辑
回复 6# flashercs
可以给个支付宝/微信 略表谢意吗
作者: flashercs 时间: 2019-7-27 22:11
回复 7# smss
微信
作者: smss 时间: 2019-7-27 22:41
回复 8# flashercs 小小心意略表寸心
作者: smss 时间: 2019-7-28 11:26
本帖最后由 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
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |