0

Bear in mind that I'm new to xml and npp..

I have a large xml file with several thousand records, and I need to change lines to make it work in an other program.

I've done most of the transformation in format, but hit a problem now.

What my xml looks like now:

</Value>
<name>C01</name>
<description>TEXT WITH VARYING NUBMER OF CHARACTERS FOR EACH LINE</Value>
</DPR>

and what i want:

<DPR>
<name>C01</name>
<description>TEXT WITH VARYING NUBMER OF CHARACTERS FOR EACH LINE</description>
</DPR>

The problem is replacing </Value> with two different things depending on if it is in a string of stands alone. The second problem I have is replacing parts of a line and keep the rest - when the part I want to keep has a different number of characters for every line.

All help is much appriciated!

  • Parsing XML with an editor is risky business. You'd be better off using a parser like XSLT or xquery. But you'd have to show a more complete sample of your document. – Paulb Oct 1 '15 at 13:41
0

Replacing </Value with </DPR> when it exists alone in the line:

Find what: ^ *</Value>

Replace with: </DPR>

Search mode: Regular expression

After that there shouldn't be any other instances of </Value> than those which are together with a string, so replacing them should be trivial. But for completeness...

Replacing [somestringhere]</Value -> [somestringhere]</description> when it exists alone in the line:

Find what: ^(<description>.+?)</Value>

Replace with: $1</description>

Search mode: Regular expression

In the above ^ stands for the start of the line, * means whitespace may or may not exist, .+? means any characters up to the first occurrence of the string after that (see here for more info on regular expressions), and $1 in the replacement string will be substituted with the matching part enclosed in parentheses in the source data.

| improve this answer | |
  • Perfect! And thank you for the extensive answer with commentery, really helps when my current level is as low as it is! – Einar Oct 2 '15 at 6:39
0

The easiest is to use regular expressions in Perl:

perl -i -p -e 's/</Value>\n<name>/<DPR>\n<name>/' yourfile.txt
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.