I have a WiX file that is updated automatically and programmatically. This file needs to have a define tag added to it, but I can't find a method for doing this with C#. Every time I try to add an element it says that it is not contained in the root element (which is true cause the "define" is a preprocessor command and is not included in the root element). In order to edit the XML tag (that is also preprocessor) there is built in functionality. Does anyone know if there is also built in functionality for define? Thanks for your help!
A:
I think you will have to edit your file in 'text' mode, not in XML mode. One possible solution is to insert special markers in your file in XML mode, e.g.
<a_very_special_marker/>
And then do a replace on these markers on the text of the file.
slurdge
2010-07-06 08:59:42
@slurdge: thanks for the quick answer. That seems overly messy to me. It is possible I suppose, but I have a lot of other work going on with the WiX files through the XML methods and to parse the entire thing to text, add that one tag, then re parse it into XML just doesn't exactly suit my needs. Thanks for the suggestion though.
Adkins
2010-07-06 09:07:57
+2
A:
If you're using an XmlWriter, use the WriteProcessingInstruction to write a processing instruction. If you're using XSLT, use xsl:processing-instruction. If you're using a different C# mechanism to create your XML, tell us - most mechanisms have facilities to create processing instructions.
Pete Kirkham
2010-07-06 09:15:19
@Pete: currently I save the XML using simply XDocument.Save(string fileName) Do you know if that has the facilities to create processing instructions?
Adkins
2010-07-06 09:29:46
@Adkins I'm not familiar with the XDocument api, but it seems to have a mechanism to get a list of the nodes in the document (DescendentNodes), and you can might be able to call `document.DescendentNodes.First().AddBeforeSelf(new XProcessingInstruction("define", "whatever"))` or similar to add a processing instruction to the start of the document.
Pete Kirkham
2010-07-06 09:39:31
The actual element looks something like this:WXSFile.AddFirst(new XProcessingInstruction("define", "whatever"));Thanks for the help. You really pushed me in the right direction.
Adkins
2010-07-06 10:43:27