Lazarus
Programming => General => Topic started by: totya on August 13, 2019, 09:13:02 pm
-
Hi!
I have a lines from a xml (I read it full manually because I need it), for example (code):
A < < B
This is mean (decode):
A < < B
Is there any built-in function in fpc/Lazarus to convert all exists xml codes (code and decode) from string to string?
Thanks!
-
htmlelements unit from fcl-xml has both EscapeHTML and UnescapeHTML functions.
-
htmlelements unit from fcl-xml has both EscapeHTML and UnescapeHTML functions.
Seems to me its working, thank you!
-
Or use XMLValueToStr() from laz2_dom (https://lazarus-ccr.sourceforge.io/docs/lazutils/laz2_dom/xmlvaluetostr.html).
-
Or use XMLValueToStr() from laz2_dom (https://lazarus-ccr.sourceforge.io/docs/lazutils/laz2_dom/xmlvaluetostr.html).
Thank you too, wp master :)
-
These two method works similar, but I don't like the result. I recreate the xml codes that way - see second line. (Insert code result garbage s variable, so I used insert quote)
procedure TForm1.Button1Click(Sender: TObject);
const
s = 'AA BB';
begin
Memo1.Lines.Add(XMLValueToStr(s));
Memo1.Lines.Add(StrToXMLValue(XMLValueToStr(s)));
//Memo1.Lines.Add(XMLValueToStr(StrToXMLValue(XMLValueToStr(s))));
Memo1.Lines.Add('');
Memo1.Lines.Add(UnEscapeHTML(s));
Memo1.Lines.Add(EscapeHTML(UnEscapeHTML(s)));
//Memo1.Lines.Add(UnEscapeHTML(EscapeHTML(UnEscapeHTML(s))));
end;
I got:
AA BB
AA &#10; BB
AA BB
AA &#10; BB
But I'd like to keep "AA BB"...
Edit:
This seems to me ugly code:
StringReplace(Value, '&#', '&#', [rfReplaceAll]);
-
But I'd like to keep "AA BB"...
Then you're not fully escaping as it's meant to be. Come to think of it, what would happen if you unescape with the incompletely escaped value? Consistency is there for a reason.
This seems to me ugly code:
It's ugly from the start: why would you ever want to do that?
-
Because this is the original xml code, and this is okay. I want only add the missing xml charcodes to the string... Shortly, this function (from the laz2_dom) works incorrectly in this situation. But with my ugly code, this will okay.