Tidy.exe - Keep space at the end of tag

Suggest, ask for or provide links to handy external tools.
Post Reply
lolo
Posts: 110
Joined: 18 Apr 2011 11:14

Tidy.exe - Keep space at the end of tag

Post by lolo »

Hello,

I would like to know if there is an option that tell to Tidy to keep space at the end of a tag when it beautify aXML.
For example:

Code: Select all

<?xml version="1.0"?>
<Test>String with space at the end </Test>
becomes (space after end has been deleted)

Code: Select all

<?xml version="1.0"?>
<Test>String with space at the end</Test>
Thanks in advance and have a nice day.
User avatar
pjj
Posts: 2108
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Tidy.exe - Keep space at the end of tag

Post by pjj »

I can't really imagine why one would want to keep trailing whitespace in between tags, but that's my problem, isn't it? :-D Anyway, a cursory look on Tidy's plethora of options indicates there's no such one that would do what you want; perhaps you'd like to add your use case to the list of Tidy's issues at Github?

Btw Rickard, you may want to use newer version of Tidy (5.4.0 instead of 5.2.0) with the next RJ TE release.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
lolo
Posts: 110
Joined: 18 Apr 2011 11:14

Re: Tidy.exe - Keep space at the end of tag

Post by lolo »

Hi pjj,

Thanks for your answer.
I need this behavior because I have to generate and send XML to a web service.
This web service use a "special" tag to get information about an order and this tag has 70 characters maximum
For example you can have :

Code: Select all

<?xml version="1.0"?>
<FreeText1>This is a comment on se</FreeText1>
<FreeText2>veral lines </FreeText2>
<FreeText3>for my example</FreeText3>
As you can see, if the truncate is done just after a space, I need to keep it intact in my XML tag.

Tidy default behavior is strange because it alter the original xml content.

Others online XML beautifier or event XML Tools plugin on Notepad++ does not have this behavior.

So, it does not matter. I really love RJ TextED!
User avatar
pjj
Posts: 2108
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Tidy.exe - Keep space at the end of tag

Post by pjj »

I see. Here https://stackoverflow.com/a/15167134 I have found a hackish solution:
Put <pre> around the xml you want to validate (this instructs Tidy not to change the whitespace), then repair the xml with output-html set to true, then remove the <pre> and \n newlines.
Perhaps that helps.

Edit:
Even when specifications may be unclear on the matter, XML culture, conventions, product features, programming habits, and general best practices are allied not only to collapse but to trim whitespace from elements that contain only text.
https://wiki.tei-c.org/index.php/XML_Wh ... y_Elements
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Post Reply