How can I perform Search&Replace on an XML file after WIX installation? - string

After installing my files using WIX 3.5 I would like to changes some values in one of my xml files.
Currently there are multiple entries like this:
<endpoint address="net.tcp://localhost/XYZ" .../>
I would like to change the localhost to the real servername wich is available due to a property. How can I perform this replacement on each entry inside this xml file? Is there a way to do this without writing an own CA?
Thanks in advance!

XmlConfig and/or XmlFile elements are your friends here.
UPDATE: Well, according to the comments below, it turns out that only part of the attribute (or element) value should be changed. This seems not to be supported by either of two referenced elements.
I would take one of the two approaches then:
Use third-party "read XML" actions, like this one
It's better than creating your own because you can rely on deeper testing in this case
Teach your build script to control the string pattern
Let's say you put `net.tcp://localhost/XYZ` to build file and your code is pointed out to take this value as a string pattern to use at install time. For instance, keep the string pattern as a Property in your MSI package. When it changes, e.g. to `net.tcp://localhost/ABC` you'll have to change nothing in your action. In this case from a XMLFile perspective you always know your FROM and TO attribute values.

If your XML configuration file is not large, you can load the file into memory and perform replace using JScript.
var s = "<endpoint address=\"net.tcp://localhost/XYZ\" .../>";
var re = /"net.tcp:\/\/localhost\//g;
var r = s.replace(re, "\"http://newhost.com/");
Here s is your complete XML file, re is the regular expression, and r would contain the result or replace.
You can read and write to public properties of Windows Installer using JScript. Yet there's still one problem: you have to read your XML file and to write it back to disk. To do it, you can use Win32_ReadFile and Win32_WriteFile custom actions from the AppSecInc. MSI Extensions library referenced by Yan in his answer.
However, it could be easier to write a complete Custom Action which will load your XML configuration file, do the replace, and write the file back to disk. To do it you can use XSLT and JScript (see an example code).

InstallShield has a built-in data driven custom action called Text Search. It basically allows for RegEx style replacements like what you are describing.
WiX doesn't have this functionality but you could write a custom action ( say using C#/DTF ) to do it for you.

There nothing in Wix, you can do to change something in a file without using a custom action. If you don't want to use CA, you can consider saving the settings in some other place e.g. User's registry and always read that setting from there

Related

Preview transformation in vscode using javascript/typescript

We are consuming apis returning json in our projects. The json from those api can contain rather large structures which need to be mapped into other large structures (usually json but could be xml or csv rarely).
We used to use dataweave (from Mulesoft) to do that, and if you're not familiar with dataweave, it's pretty good at that sort of mapping. It let's you define a sample input, and while editing the dataweave it shows you a preview of the result in a separate pane.
For some apis we switched to using nodejs (because it offers better control and debugging than Mule, long story). But I'd really like the same mapping experience as dataweave.
So I guess the question is: can I use vscode to define an input file in a directory, a transformation file in javascript and have the resulting mapped output display in a pane which is updated live?
Is there some plugin offering that? Couldn't find it.
My understanding is the following:
You have a mule workflow which needs to read a file(you edited the file in vscode) and execute a server side javascript (nodjs) to transform the file and after the result is obtained, the mapped result will be pushed into a web page ? right ?
All happen under a given mule workflow right? and you are wondering there is any mule connector to do this process ? right ?

How can I add a comment to a LabVIEW file using Python 3

I am trying to create a unique id and attach it to a LabVIEW file so that later I can read back that id and know I am looking at exactly the same file. I must be able to generate the id and read it back programmatically. The information must be hidden from the user accessing the file and persist across operating systems and storage mediums.
I was thinking of just adding it into the file 'comment' section, but it appears the Windows no longer supports file comments.
Any ideas?
I would suggest using the Set Tag method on the VI (with persistence) and saving multiple copies of the VI using the Save Instrument method, where each copy would then have its own unique value of the tag. Note that the method is defined as a scripting method, so you would probably need to enable scripting in the LV options to access it.
I don't think there's any API for enumerating tags, so there would be no way to find the value unless you know what the tag is called. Obviously, it's encoded somewhere in the VI file itself, and presumably it would be possible to extract a list of tags if you know the structure of the file, but that's not knowledge I would expect most students to have.
I'm not sure if you can call the set tag method from Python using an external connection to VI server, but certainly the LV code for this should be pretty simple - basically a for loop with ID generation, a couple of method calls and saving a CSV file so you can keep track of which ID belongs to which student. If you use existing IDs, you don't even need to generate and save the IDs.

Is there any way to remove or not to include certain xml elements while creating from mpxj library?

currently when working with mpxj library, generated task xml will have following attributes
<Task>
<UID>0</UID>
<ID>0</ID>
<Name>Naruto Uzumaki</Name>
<Active>1</Active>
<Manual>0</Manual>
......
......
</Task>
I do not want Active and Manual tags present in the generated xml, is there any way to achieve this? Kindly help.
Thanks in Advance.
I'm not sure of MS Project's behaviour if these values are removed entirely... if it would give you the defaults you are expecting when it reads the file. On that basis it is not something you can change in MPXJ itself.
However, one simple way to achieve what you want would be to apply an XSL transformation to the generated XML to remove the elements you don't want. The answer to this StackOverflow question provides an example of how this could be done.
Assuming you are using Java and you are writing to a stream you can probably use one of the mechanisms highlighted in this StackOverflow question to take the output directly from MPXJ and pass it through an XSL transformation.

Alfresco node-browser.get.js webscript

At this location in this jar file alfresco-remote-api-5.0.d.jar\alfresco\templates\webscripts\org\alfresco\slingshot\node-browser\ there is a webscript. But this webscript consist to 2 files (node-browser.get.desc.xml and node-browser.get.json.ftl ) There isn't the node-browser.get.js file.
I want to know what is done in this fil. I want to select categories and include certains aspects (i have added to categories) in the selection.
Thank you.
Javascript file is not mandatory while creating webscript.
Below is the URL of source file which is getting called on your specified webscript.
https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V5.0.d/root/projects/remote-api/source/java/org/alfresco/slingshot/web/scripts/NodeBrowserScript.java
Below is context file for java file.
https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V5.0.d/root/projects/remote-api/config/alfresco/web-scripts-application-context.xml
check bean with webscript.org.alfresco.slingshot.node-browser.node-browser.get
Id.
you need to change in that if you want to customize it.
Usually a webscript is made of 3 parts:
a description file (in your case node-browser.get.desc.xml) which
uses a description language to define many aspects of the
webscript, like security, transaction management and so on
a Server-Side Javascript js file that consists of the business logic that is performed by
the script. In your case you don't have the node-browser.get.js file
because this happens to be a Java backed webscript, that is a
webscript whose business logic is written in Java and not in
Server-Side Javascript.
a Freemarker Template file, node-browser.get.json.ftl, which contains
the presentation logic (view) that has to show the results of the invocation.
In order to achieve what you're looking for about selecting categories and include certains aspects, you'd better learn more about how webscripts work and moreover how to configure/customize Alfresco's interface.
You'd better look at these tutorials in order to get more info.

Spring "Integrating Data" Getting started guide - using variables in the integration.xml file

I've worked through the "Integrating Data" guide on the Spring website and have been trying to determine how to use configuration settings (substitution) in the integration.xml file rather than hard code various items. This is primarily driven by a desire to externalise some of the configuration from the XML and take advantage of Spring Boot's ability to allow for externalised configuration.
I've been trying to determine the solution for a while now and thought it's likely to be an easy answer (for those who know how).
In the snippet below (taken from the guide) I've used ${outputDir} as a placeholder for a configuration item I'll pass into the application:
<file:outbound-channel-adapter id="files"
mode="APPEND"
charset="UTF-8"
directory="${outputDir}"
filename-generator-expression="'HelloWorld'"/>
Essentially, I'm trying to determine what I need to do to get the ${outputDir} substitution working.
As part of working through the problem I reduced the code down to a demo that I've uploaded to BitBucket:
integration.xml will just copy files from a file:inbound-channel-adapter directory to a file:outbound-channel-adapterdirectory
The Application class uses Spring Boot to load the configuration into a DemoIntegration instance and it's the fields in that instance that I'd like to substitute into integration.xml at runtime.
Unless I'm mistaken (when I get this to work) I should be able to override the inputDir and outputDir items in integration.xml.
Your integration.xml references ${inputDir}, which is not there.
Just to make it work with the existing config, add/change the application.properties file in your classpath with inputDir=/tmp/in and outputDir. This way it matches with your used vars in the config file.
If you want to stick with your naming, then change the XML to use ${demo.inputDir}. These are the names you are using in your existing application.properties.
And if you want to stick to your #ConfigurationProperties, then you can put #{demoConfigration.inputDir} in the XML to access the bean, where your config is stored. Note, that your code currently fails (at least for me) as you basically define the bean twice (once per #EnableConfigurationProperties and once by #ComponentScan+#Component on the config.

Resources