• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

Notepad++ to autoformat xml?

lozina

Lifer
Sep 10, 2001
11,711
8
81
IS there a way to get Notepad++ to autoformat xml ?

i.e. wrap it on each xml element and perform indenting ?

at least something so this chunk of xml data I'm looking at is more readabe
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Maybe you can do a replace in MS Word for something along the lines of "^p</tag" to "</tag>". The ^p in MS Word is the paragraph character, and that can really help clean things up too. Also, if you were wondering, "^t" is the tab character. So you can do replacements for things like, "^p^p^t^t</tag>" to "</tag>".

And for what it's worth, I realize that my period is not inside the quotes, I didn't want to put it in there because I didn't want to confuse anyone who might get confused. Not necessarily the OP but anyone who reads it.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Could write a little parser to handle it. Searches for <something>, pushes it onto a stack. Indents whenever it sees a new <something>, when it sees </something> it reduces indentation by 1 and pops "something" off the stack. Also, insert newline when it seems <something> or </something>.

Probably a 10-line Perl script could do it neatly, unless there's some subtlety I'm missing. This of course assumes your data fields don't have XML-like data in them (though if it's escaped, then you'd just need to change your regex a little to handle it).