Search code examples
msdeploywebdeploy

Web Deploy parameterization of an XML config file where settings are embedded in CDATA elements


During MSDEPLOY.EXE deployment, I am trying to squirt a parameter into an XML configuration file but the configuration values are stored in CDATA elements. Here are the contents of the file, called paths.xml:

<?xml version="1.0" encoding="UTF-8"?>
<course>
  <questionnaires><![CDATA[https://www.site.com/somepage.asp]]></questionnaires>    
</course>

I need to transform that URL into something different, but I can't figure out the correct XPATH and syntax for my parameters.xml file, here is what I've got now:

<?xml version="1.0" encoding="utf-8"?>
<parameters>
  <parameter name="QuestPath" description="Questionnaires path" defaultValue="&lt;questionnaires&gt;&lt;![CDATA[https://www.foo.com/somepage.asp]]&gt;&lt;/questionnaires&gt;" tags="">
    <parameterEntry kind="XmlFile" scope="paths.xml$" match="/course/questionnaires" />
  </parameter>
</parameters>

I had very little luck referencing the CDATA element to replace it, so you can see I'm now trying to replace the entire questionnaire element including its CDATA contents. I had to do some escaping of the embedded angle-brackets so parameters.xml wasn't rejected due to invalid XML format.

Now, the resultant paths.xml ends up like:

<?xml version="1.0" encoding="UTF-8"?>
<course>
  <questionnaires>https://www.foo.com/somepage.asp</questionnaires> 
</course>

So, something has resolved the CDATA element down to its contents only, and CDATA no longer appears in paths.xml which I assume will cause the program that reads it to fail. Help!


Solution

  • Okay - I found a much simpler solution. In conjunction with the developer involved in housing this config XML file on our server, we changed it so the elements just contain the raw URLs, completely dispensing with the CDATA structures.

    After testing that the consuming application still appeared to work fine, we agreed they were not needed and therefore I was able to do normal XmlFile replacements on nodes referenced like:

    ...match="/course/questionnaires/text()"