google / cap-library

Common Alerting Protocol Library
Apache License 2.0
80 stars 30 forks source link

Improve readability of output by adding newlines between each tag #34

Open sschiavoni opened 9 years ago

sschiavoni commented 9 years ago

Original issue 35 created by yuch@google.com on 2012-10-03T18:06:16.000Z:

What steps will reproduce the problem?

If you enter a CAP <alert> without any new lines, the output also wouldn't have any newlines. So for example, sometimes a CAP message is 1 long line. As a result, any errors and warnings will be difficult to identify in that jumble, because they're line-based.

What is the expected output? What do you see instead?

Add new lines in between <tags> for the output.

What version of the product are you using? On what operating system?

Please provide any additional information below.

sschiavoni commented 9 years ago

This is doable, but requires to introduce yet another XML parser (which is fine, I guess).

The only problem I see is that if you provide a URL, or copy-paste from a file, the errors will be reported on a line which does not correspond anymore to the original one. @azamanyan, should we ho ahead?

shakusa commented 9 years ago

A pretty simple heuristic may work here; something like "if not a url and number of newlines in input is less than 5, pretty-print and continue".

On Mon, Dec 1, 2014 at 10:37 AM, Stefano Schiavoni <notifications@github.com

wrote:

This is doable, but requires to introduce yet another XML parser (which is fine, I guess).

The only problem I see is that if you provide a URL, or copy-paste from a file, the errors will be reported on a line which does not correspond anymore to the original one. @azamanyan https://github.com/azamanyan, should we ho ahead?

— Reply to this email directly or view it on GitHub https://github.com/google/cap-library/issues/34#issuecomment-65081853.

azamanyan commented 9 years ago

With the suggested heuristic, I think this will work well since we wouldn't modify CAP that already included newlines for formatting.

sschiavoni commented 9 years ago

Sounds good.

Just one note: we won't be able to easily pretty-print the XML when it is not a well-formatted XML (i.e., when the XML parser throws a fatal exception). In this case we will need to fall-back to the original input formatting.