I would like to remove a comment tag from a XmlDocument using Inno Setup. My xml looks approximately like this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="AuthenticationService">
<!--
<endpoint contract="System.Web.ApplicationServices.AuthenticationService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
-->
</service>
</services>
</system.serviceModel>
</configuration>
I would like to uncomment using Inno Setup the section
<endpoint>
...
</endpoint>
, so remove the comment tags around it.
I found from here that this could be done using the following procedure:
- Get the value of the comment node
- Create a new XmlNode with the value from step 1
- Delete the comment node
- Add the new node from step 2 to the DOM tree
Unfortunately the example in the answer is in C#.
if (commentNode != null)
{
XmlReader nodeReader = XmlReader.Create(new StringReader(commentNode.Value));
XmlNode newNode = xdoc.ReadNode(nodeReader);
commentNode.ParentNode.ReplaceChild(newNode, commentNode);
}
So far I haven't found how to implement XmlReader with Inno Setup. So, I tried this.
APath := '//configuration/system.serviceModel/services/service/comment()';
XMLCommentNode := XMLDoc.selectSingleNode(APath);
if Not (IDispatch(XMLCommentNode) = nil) then
begin
Log('Remove comment tag ' + APath + ' value is: ' + XMLCommentNode.Text);
newNode := XMLDoc.createElement(XMLCommentNode.Text);
XMLCommentNode.ParentNode.ReplaceChild(newNode, XMLCommentNode);
end
The text value of XMLCommentNode seems correct to me when I write it to log.
[08.59.44,190] Remove comment tag //configuration/system.serviceModel/services/service/comment() value is:
<endpoint contract="System.Web.ApplicationServices.AuthenticationService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
However, when creating a new element from that I get an error message
Internal error: Expression error 'Runtime error (at 20:2651):
msxml3.dll: This name may not contain the '
' character:
-->
<-- <endpoint contract="System.Web.ApplicationServices.AuthenticationService">
<identity>
<dns value="localhost" />
...
'
How proceed and correct this error?