简体   繁体   中英

Notepad++ Select text within multiple tags

hope someone can help. I have a pretty big XML file that needs tidying up. Basically some line breaks are present which we need to get rid of. There are roughly 19,000 " <Location> " tags with text between. Is there a way to have NPP search for all <Location> tags, select it up to the closing tag and perform join lines? 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:

<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! Hope this makes more sense.

I'm assuming that each <Location> tag has a matching closing tag of </Location> like this:

<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 . Enter </Location>\\r\\n as the Find text and put in </Location> as the Replace text.

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". You can install it with the Plugin Manager. It offers several options:

  • linearize
  • beautify with and without linebreaks

You could give it a try.

As Lars mentioned there is a plugin, and it is great. 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

2)by replacing </location> with </location>\\r\\n

Have a try with:

Click on Ctrl + H

Find what: (?=<Location>)([^\\r\\n]+)\\R(?!<location>)
Replace with: $1

Make sure that Regular Expression is checked then click on Replace all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM