Read XML Element from file - Advanced Installer Community
markf
Posts: 4
Joined: Thu Nov 05, 2015 3:44 pm

Read XML Element from file

I am performing an update on an existing system, within the system there is an xml file called settings.xml within this file there is an element called DatabaseLocation.

Mocked up Settings.XML file for example

Code: Select all

<ApplicationSettings>
     <Property1>false</Property1>
     <DatabaseLocation>j:\MYAppFiles</DatabaseLocation>
</ApplicationSettings>
I can locate the file using the file browse dialogue, the issue I am struggling with is how to read the databaseLocation element to use as a property folder.

I have spent two day trying to use the xml search (in custom behaviors) and the XML File options in file. XML Search does not work as I cannot see an options to search for element name.

I would like the value of the xml element to end up in a install parameter so that I can use in a property based folder.

Please can someone indicate the correct procedure for extracting the value

Many Thanks M
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Read XML Element from file

Hello and welcome to Advanced Installer forums,

In order to have a better view about this, please send us the .AIP(project file) and a sample .xml configuration file and the elements we should search in the XML file.

Also, please take a look on the Keep web.connfig settings from an older install path forum thread where you can find a sample project that implements your scenario.

Should there be any difficulty you encounter implementing something, please do not hesitate to contact me and I will gladly assist.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
markf
Posts: 4
Joined: Thu Nov 05, 2015 3:44 pm

Re: Read XML Element from file

Thanks Dan.

I have tried the example the issue I have is that the XML file was created using Advanced installer but we did not use any attributes just elements (Which contains text). I can use the search to retrieve the information if there was an attribute what I want to know is how I retrieve the element text by element name.

My project is rather large and contains commercial information I will try and simplify it and add it to this message.

Regards

Mark
markf
Posts: 4
Joined: Thu Nov 05, 2015 3:44 pm

Re: Read XML Element from file

I have added sample projects.

Create XML creates the XML file (Note no attrbutes on the xml elements). This product has already been shipped so I cant change the XML file.

Second project browses for settings file (via dialog) and then I am stuck as I cant see a way to retrieve the <NetworkFolder> element by its name. I would like to get the contents of this element and store in the DBFolder parameter.

Many Thanks

Mark
Attachments
Projects.zip
(8.13 KiB) Downloaded 381 times
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Read XML Element from file

Hello Mark,

Please note that we have added support in Advanced Installer to search an XML element text by the XML element name only starting with version 12.5 of Advanced Installer. So, to achieve what you want you should use at least version 12.5 of AI.

Also, please note that all XML locator searches defined in "Search" page are performed at the very beginning of the installation during the "AI_XmlLocator" custom action before the dialogs are displayed. So, to configure the "AI_XmlLocator" action to also execute on one of your installation dialog (e.g. after the "MY_SettingFile" property is set) you can workaround like this:
1. go to "Dialogs" page and select the "FolderDlg" dialog
2. on the [Next] button add a published event like this:
  • Control Event: Execute custom action
    Argument: BrowseForFile
    Condition: MY_SettingFile
3. go to "Table Editor" page and select the "ControlEvent" table
4. edit the "Argument" field of the "FolderDlg -> Next -> DoAction" row like this: AI_XmlLocator
5. rebuild and test again your project

Please note the above workaround requires at least an "Enterprise" project type to be used.

Also, as a side note please be aware that instead of using a private property name for your "DBFolder" property (used to create the property-based folder) you should use a public property name (i.e. DB_FOLDER). This way the value of your property won't be reset when the installation passes from Wizard Dialogs Stage to the Install Execution Stage.

Here it is attached a modified version, using AI 12.6.1, of your "REadXML.aip" project which implements your requirements.
REadXML.aip
(24.56 KiB) Downloaded 359 times
If you have any questions or doubts just let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
markf
Posts: 4
Joined: Thu Nov 05, 2015 3:44 pm

Re: Read XML Element from file

Thank you Dan, this seems to do exactly want I want.

Sorry about the delay but I had to renew my license to download 12.6.

Many Thanks

Mark
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Read XML Element from file

You're always welcome Mark.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
vikasb
Posts: 9
Joined: Thu May 28, 2020 11:20 am

Re: Read XML Element from file

Hi Daniel,
In this scenario I have to take setting file path from previous installation location which is the same as new one.
which I can take using [Application_Dir] .
Is it necessary to use that custom action of BrowseForFile?
In the sample project, you have taken file from browse dialog, which I don't required.
So How to trigger my XML search condition?
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Read XML Element from file

Hello,
Is it necessary to use that custom action of BrowseForFile?
No, this will not be necessary. However, the above user had this scenario, therefore the solution also included that custom action.

If I understand correctly, you want to perform the search during an upgrade scenario. There might be some problems with this scenario, as the APPDIR property (the "Application Directory" where your configuration file is located) is not resolved at the time when the search is executed.

For more details about this, please have a look over the "XML search does not work" thread.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”