通过Notepad++整理XML个相同类型的代码
Organizing XML code of the same type via Notepad++
伙计们,我在 xml 中有很多代码,目前采用以下方式
<Query
class="type:x-xmb/folder-pixmap"
key="seg_canyon_preset_001"
attr="seg_canyon_preset_001"
src="#seg_canyon_preset_001_item"
/>
我需要做成这样
<Query class="type:x-xmb/folder-pixmap" key="seg_canyon_preset_001" attr="seg_canyon_preset_001" src="#seg_canyon_preset_001_item"/>
class=, key= 和 src= 可能不同,所以我需要一种方法让这种格式的各种代码都在一行上,即使它们可能不同,因为显示如下:
<Query
class="type:x-xmb/module-action"
key="clock_icon_015_item"
attr="clock_icon_015_item"
/>
假设属性中没有 spaces
- Ctrl+H
- 查找内容:
(?:<Query|\G(?!/>))\K\s+([^>\r\n]+)
- 替换为:
(A space 和 </code>)</li>
<li><strong>检查</strong> <em>匹配大小写</em></li>
<li><strong>检查</strong> <em>环绕</em></li>
<li><strong>检查</strong> <em>正则表达式</em></li>
<li><kbd>全部替换</kbd></li>
</ul>
<p><strong>解释:</strong></p>
<pre><code>(?: # non capture group
<Query # literally
| # OR
\G # restart from last match position
(?!/>) # If not followed by end tag
) # end group
\K # forget all we have seen until this position
\s+ # 1 or more spaces, including linebreaks
( # group 1
[^>\r\n]+ # 1 or more any character that is not > of linebreak
) # end group
截图(之前):
截图(后):
伙计们,我在 xml 中有很多代码,目前采用以下方式
<Query
class="type:x-xmb/folder-pixmap"
key="seg_canyon_preset_001"
attr="seg_canyon_preset_001"
src="#seg_canyon_preset_001_item"
/>
我需要做成这样
<Query class="type:x-xmb/folder-pixmap" key="seg_canyon_preset_001" attr="seg_canyon_preset_001" src="#seg_canyon_preset_001_item"/>
class=, key= 和 src= 可能不同,所以我需要一种方法让这种格式的各种代码都在一行上,即使它们可能不同,因为显示如下:
<Query
class="type:x-xmb/module-action"
key="clock_icon_015_item"
attr="clock_icon_015_item"
/>
假设属性中没有 spaces
- Ctrl+H
- 查找内容:
(?:<Query|\G(?!/>))\K\s+([^>\r\n]+)
- 替换为:
</code>)</li> <li><strong>检查</strong> <em>匹配大小写</em></li> <li><strong>检查</strong> <em>环绕</em></li> <li><strong>检查</strong> <em>正则表达式</em></li> <li><kbd>全部替换</kbd></li> </ul> <p><strong>解释:</strong></p> <pre><code>(?: # non capture group <Query # literally | # OR \G # restart from last match position (?!/>) # If not followed by end tag ) # end group \K # forget all we have seen until this position \s+ # 1 or more spaces, including linebreaks ( # group 1 [^>\r\n]+ # 1 or more any character that is not > of linebreak ) # end group
截图(之前):
截图(后):