[英]Notepad++ Select text within multiple tags
hope someone can help. 希望有人可以帮忙。 I have a pretty big XML file that needs tidying up.
我有一个很大的XML文件,需要整理。 Basically some line breaks are present which we need to get rid of.
基本上存在一些换行符,我们需要消除这些换行符。 There are roughly 19,000 "
<Location>
" tags with text between. 大约有19,000个“
<Location>
”标签,中间带有文本。 Is there a way to have NPP search for all <Location>
tags, select it up to the closing tag and perform join lines? 是否有办法让NPP搜索所有
<Location>
标签,将其选择到结束标签并执行连接行? Join lines fixes the problem, but it's going to take all day checking each one. 联接线可以解决此问题,但是需要花费一整天的时间来检查每个联接器。
EDIT: Sorry, don't think I explained it very well! 编辑:对不起,不要以为我解释得很好! So basically there are more tags present in this XML document, for example:
因此,基本上,此XML文档中存在更多标签,例如:
<AccomRef>
<Code>BT1</Code>
<Location>Sometimes the text in here has line breaks
like this</Location>
</AccomRef>
I guess ideally I need to keep the tags nice and tidy with breaks after each closing tag, but just ensure that all location text is joined without breaks. 我想理想情况下,我需要在每个结束标记之后保持标记的整洁,有断点,但只要确保所有位置文本都无间断地连接即可。 I tried CTRL+A > CTRL+J but that then makes the file incredibly hard to read!
我试过了CTRL + A> CTRL + J,但这会使文件难以阅读! Hope this makes more sense.
希望这更有意义。
I'm assuming that each <Location>
tag has a matching closing tag of </Location>
like this: 我假设每个
<Location>
标记都具有一个匹配的</Location>
结束标记,如下所示:
<Location>something</Location>
<Location>another</Location>
<Location>and again</Location>
And you want to get to 而你想去
<Location>something</Location><Location>another</Location><Location>and again</Location>
If so, go to the Replace
dialog (Ctrl + H) and pick Extended
in Search Mode
. 如果是这样,请转到“
Replace
对话框(Ctrl + H)并选择“在Search Mode
Extended
Search Mode
。 Enter </Location>\\r\\n
as the Find
text and put in </Location>
as the Replace
text. 输入
</Location>\\r\\n
作为“ Find
文本,并输入</Location>
作为“ Replace
文本。
This will then replace each closing tag + line break with just the closing tag. 然后,这将仅用结束标记替换每个结束标记+换行符。
I'd try this out on a sample file before doing it on your actual data though! 不过,我会先对示例文件进行尝试,然后再对您的实际数据进行处理!
Edit: Now that you've clarified your question, my answer doesn't really help. 编辑:现在您已经澄清了问题,我的回答并没有真正的帮助。
There is a Plugin "XML Tools". 有一个插件“ XML工具”。 You can install it with the Plugin Manager.
您可以使用插件管理器进行安装。 It offers several options:
它提供了几种选择:
You could give it a try. 您可以尝试一下。
As Lars mentioned there is a plugin, and it is great. 正如Lars提到的,有一个插件,它很棒。 But as understand your problem you have deal with situation like this
但是随着了解您的问题,您已经处理了这样的情况
<location>some location</location>
<location>some
location2</location>
<location>some location3</location>
and want to have something like this 想要有这样的东西
<location>some location</location>
<location>some location2</location>
<location>some location3</location>
And if this your problem, you could solve it in two moves: 如果这是您的问题,则可以通过两个步骤解决:
1)by replacing \\r\\n
with blanks 1)通过用空格替换
\\r\\n
2)by replacing </location>
with </location>\\r\\n
2)用
</location>\\r\\n
替换</location>
Have a try with: 尝试一下:
Click on Ctrl + H 点击Ctrl + H
Find what: (?=<Location>)([^\\r\\n]+)\\R(?!<location>)
查找内容:
(?=<Location>)([^\\r\\n]+)\\R(?!<location>)
Replace with: $1
替换为:
$1
Make sure that Regular Expression
is checked then click on Replace all 确保选中
Regular Expression
,然后单击全部替换
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.