Lazarus

Programming => General => Topic started by: c600g on November 30, 2021, 05:24:01 pm

Title: XML parsing of ampersand character
Post by: c600g on November 30, 2021, 05:24:01 pm
I am using ReadXMLFile() to parse a string stream containing XML. One of the attributes I am parsing includes a properly escaped ampersand character ("&"). When I get the attribute value, the entity is automatically converted to "&" in the string. Is there a way to prevent this from happening?

Thanks much,
  Alan
Title: Re: XML parsing of ampersand character
Post by: winni on November 30, 2021, 07:57:37 pm
Hi!

Double the escaped ampersand:

&&

Or if it is inside an URL then use the hexadecimal value:

%26


Winni

Title: Re: XML parsing of ampersand character
Post by: c600g on November 30, 2021, 08:17:08 pm
Winni,

Thanks for the reply. However, I cannot control the input values to this attribute - they are sent in by a calling application over which I have no control. I simply want the attribute's value to *not* convert the "&" to "&" when I get the node's value (using TDOMNode.NodeValue).

Cheers,
  Alan
Title: Re: XML parsing of ampersand character
Post by: SymbolicFrank on December 03, 2021, 06:13:10 pm
I think it should work if you include laz2_XMLRead, instead of just XMLRead. That way, ReadXMLFile has an additional parameter:

Code: Pascal  [Select][+][-]
  1.   TXMLReaderFlag = (
  2.     xrfAllowLowerThanInAttributeValue,
  3.     xrfAllowSpecialCharsInAttributeValue,
  4.     xrfAllowSpecialCharsInComments,
  5.     xrfPreserveWhiteSpace
  6.     );
TinyPortal © 2005-2018