Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert selection XML to text (<> => &lt;&&gt;) #27

Open
Sopor opened this issue Dec 31, 2019 · 5 comments
Open

Convert selection XML to text (<> => &lt;&&gt;) #27

Sopor opened this issue Dec 31, 2019 · 5 comments

Comments

@Sopor
Copy link

Sopor commented Dec 31, 2019

When i convert text to XML by using the Convert selection XML to text (<> => &lt;&&gt;) it seems to not do anything for the apostrophe (single quote) even if that should be &apos;

&lt;
&gt;
&amp;
'
&quot;
@Sopor
Copy link
Author

Sopor commented Dec 31, 2019

Btw, is this really correct?

image

When i want to convert text to XML i need to use Convert selection XML to text and not Convert selection text to XML. The (<> => &lt;&&gt;) seems to be correct, though.

@github-canni
Copy link

github-canni commented Jun 15, 2020

I tried with v. 3.0.4.3 and it works for me with &amp, though I would expect a slightly different behavior

Expected behaviour:

Function to de-/encode special chars within selected tags (which are not marked as CDATA):

chars are replaced with ' " & < > and vice versa

It also encodes tags though if selected, so I would expect it to encode only the content of a tag
(Use Case: Usually I would like to select whole parts of a file and then "encode" content of all non-cdata tags)

@LetMeSleepAlready
Copy link
Collaborator

The de/encode is a simple text replacement algo. It has no notion of XML itself other than that it has to replace certain texts.

Lets explore the use cases:

Use case 1:
I have text, which I need to insert into XML.. however it might have illegal/reserved characters that will mess up the XML format. Hence, I select the text that I inserted and run 'Convert selection XML to text'... now my text is valid XML text.

Use case 2: I have some text node in XML that is encoded. Without using a full XML parser, I select this text and then run 'Convert selection text to XML. Now my selection is regular text and I can copy/paste it somewhere.

Use case 3:
I copy/pasted some & encoded text which was part of a cookie/URL-query/etc and want to decode it to XML. I select all and run 'Convert selection text to XML'. I will now have an XML document that I can work with.

Neither of these use cases require CDATA knowledge. Can you maybe describe your use case in detail?

@mikekaganski
Copy link

As described in a Python article dedicated to XML escaping [1], there are two separate cases to consider when escaping: CDATA and attributes. In the former case, there's no need to handle quotes; in the latter, quotes should be treated.

It seems logical to have dedicated functions here for the two cases; or maybe be smart to check the context (but then it would be not very flexible for cases where context in not clear, as in a temporary file without proper XML structure used for intermediate work). Currently (in version 3.0.4.3) the function Escape characters in selection (<> → &lt;&gt;) escapes everything including quotes in all positions.

[1] https://wiki.python.org/moin/EscapingXml

@morbac
Copy link
Owner

morbac commented Nov 5, 2020

For information, the xmltools options dialog let you choose which character must be handled by text/xml conversion functions:

2020-11-05_08h16_03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants