Recent

Author Topic: XML parsing of ampersand character  (Read 4797 times)

c600g

  • New Member
  • *
  • Posts: 38
XML parsing of ampersand character
« 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

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: XML parsing of ampersand character
« Reply #1 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


c600g

  • New Member
  • *
  • Posts: 38
Re: XML parsing of ampersand character
« Reply #2 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

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: XML parsing of ampersand character
« Reply #3 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