Web.config XML Transformation with escape character RRS feed

  • Question

  • User-1945300946 posted

    My ASP.net application has web.config with this appSettings key.
    <add key="XmlTag" value="Test"/>

    And the value i want to transform has "greater than' sign i.e.
    <add key="XmlTag" value=">~NewValue" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

    When the value gets transformed it transforms value to
    <add key="XmlTag" value="&gt;~NewValue"/>

    This is the same case if i escape the "greater than' sign in the web.config.
    <add key="XmlTag" value="&gt;~NewValue" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

    What do i do in my transformation configuration file so that when the file gets transformed, it adds the ">" sign?

    Thursday, May 21, 2020 5:31 PM

All replies

  • User-474980206 posted

    ">" is not valid in an xml attribute value, it should be "&gt;". when the xml is parsed to a dom the text value will be ">"

    Thursday, May 21, 2020 6:59 PM
  • User-1945300946 posted

    @bruce as i mentioned, i tried "&gt;" too but it doesn't get transformed to ">" but stays as "&gt;"

    Thursday, May 21, 2020 7:09 PM
  • User-474980206 posted

    an attribute with "<" in its value is not valid in web.config file. the transform is working correctly.

      <add key="XmlTag" value="&gt;-NewValue"/>

    is the correct way to specify a "<".

    Thursday, May 21, 2020 8:03 PM
  • User-1945300946 posted

    @bruce i tried that too i.e.

    <add key="XmlTag" value="&gt;~NewValue" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

    and it ended up changing value to this:

    <add key="XmlTag" value="&gt;~NewValue" />

    So no change at all.

    Friday, May 22, 2020 1:12 AM