Reformat xml (html) function

Discussion Forums discussion Reformat xml (html) function

This topic contains 5 replies, has 3 voices, and was last updated by  horus 1 year, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
Author Posts
Author Posts
January 29, 2013 at 2:04 pm #19644

horus
Member

Since there is no search function in this new version of forum, sorry that I have to ask this question:

Is there a function (or addon) to reformat xml strings? For example, I have an xml element like this:
aaaabbbb

I would like a function to reformat it nicely and output something like:

aaaa
bbbb

February 1, 2013 at 2:45 pm #19646

horus
Member

My example was badly formatted…. so let’s me write the xml again using [ and ]

[a]aaaa[b]bbbb[/b][c attrib="cccc" /][/a]

[a]
aaaa
[b]
bbbb
[/b]
[c attrib="cccc" /]
[/a]

February 4, 2013 at 10:14 pm #19648

aland
Member

Not sure if it’s a great solution, but I would just use find replace allowing backslash expressions, eg:
first find: ] replace: ]\n, second find: [ replace: \n[
then use find: ^\n replace: (nothing) to remove any blank lines.

There’s a magnifying glass in top right for search, but it seems broken. Just use google http://www.google.com/search?q=site:pnotepad.org/forums to search

February 5, 2013 at 9:52 am #19649

horus
Member

As a matter of fact, I’m already using the method you mentioned as a temporary incomplete workaround.

The problem with this method is that there is no indentation and you can’t easily see the level. (In my second post, I had put in some spaces but WordPress removed them all!)

February 6, 2013 at 9:34 pm #19653

simon
Key Master

I normally use HTML Tidy to do this job for me. See the docs site for configuration:

http://pnotepad.org/docs/tools/xml_formatting

February 7, 2013 at 4:26 pm #19657

horus
Member

Thanks.

OK, if my guess is correct, I have to search “HTML Tidy” in Google and download the “tidy.exe” from their website.

Could you make the words “HTML tidy” into a hyperlink to point to http://tidy.sourceforge.net/ please?

However, I’m unable to reformat xml string as suggested by that webpage of yours. I got these errors:
HTML Tidy: unknown option: w
HTML Tidy: unknown option: l
Error: Can’t open “CRLF”
Error: Can’t open “–tab-size”
Error: Can’t open “4″

I listed out tidy.exe options and it seems that “-newline” and “–tab-size” are not options. Something has changed?

Moreover, it took me some time to figure out what I was supposed to do! Maybe a little bit more explanation in that page is preferable.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.