aldebaran
Posts: 23
Joined: Wed Dec 05, 2007 4:04 pm
Location: Hannover, Germany
Contact: Website

xml file substituting attribute value of wrong node

In trying to substitute a value in an xml file on install (i.e. it's an "enterprise" kind of project allowing xml files to be altered), the installer substitutes the attribute value of the "wrong" node. Consider the three xml files below:

a) original xml file

Code: Select all

<?xml version="1.0" standalone="yes"?>
<root>
  <elem id="elem1">
    <child name="name1" value="dummyValue" />
  </elem>
  <elem id="elem2">
    <child name="name2" value="origValue" />
  </elem>
</root>
b) desired xml file after install

Code: Select all

<?xml version="1.0" standalone="yes"?>
<root>
  <elem id="elem1">
    <child name="name1" value="dummyValue" />
  </elem>
  <elem id="elem2">
    <child name="name2" value="substValue" />
  </elem>
</root>
c) resulting xml file after install (as of now)

Code: Select all

<?xml version="1.0" standalone="yes"?>
<root>
  <elem id="elem1">
    <child name="name1" value="substValue" />
  </elem>
  <elem id="elem2">
    <child name="name2" value="origValue" />
  </elem>
</root>

NB:

a) the value "elem2" of the id attribute is used as an identifier for the second "elem"-node
b) the value "name2" of the name attribute is used as an identifier for the second "child"-node
c) my xml file "layout" is therefore

Code: Select all

root
  elem
    child
d) "help" did not help :-)
e) I may have missed a forum answer; this may even be a faq, but I did search for "xml file" and looked into the first 80 hits (of approx 600).
f) this is AI 7.2.1; 8.9 fails, too

Questions:
1) Is the above achievable?
1.1) if "yes", are there any examples?
1.2) if "yes", may I upload my sample project somewhere?
Bogdan
Posts: 2791
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: xml file substituting attribute value of wrong node

Hi,

The desired requirements can be fulfilled with Advanced Installer. However, to be sure I understand exactly what you are trying to accomplish, is the XML file you are trying to update already present on the machine, or it will be deployed with your package?

If it will be deployed with your package you can look at our article that explains how to import and update the XML at install time.

If you want to update a file already present on the machine you need to use the instructions from the above article too, but along with our custom XML search.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
aldebaran
Posts: 23
Joined: Wed Dec 05, 2007 4:04 pm
Location: Hannover, Germany
Contact: Website

Re: xml file substituting attribute value of wrong node

Hi,
Bogdan wrote: [...]
However, to be sure I understand exactly what you are trying to accomplish, is the XML file you are trying to update already present on the machine, or it will be deployed with your package?

If it will be deployed with your package you can look at our article that explains how to import and update the XML at install time.
[...]
the to be edited xml file will be deployed on executing the setup.

I did already read the documentation, unfortunately it doesn't really clarify things. In my example setup project I'm using "New XML File" to create a file of type "XML File (Windows Installer)". This has the same name as the to be edited xml file of type "XML-Dokument".

I do not use "Import, XML Files...". The latter, I see, completely mirrors the structure of the to be installed xml-document. This is of no use to me, as the underlying xml-document may over time get additional nodes (e.g. "elem"-nodes). Using identifiers in my eyes it still ought to be possible to pick the right attribute. Yet, I do not know how to do it. Is there some example aip achieving the initially posted task?
Bogdan
Posts: 2791
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: xml file substituting attribute value of wrong node

We don't have any samples because the editor is quite straight forward, no major problems were encountered by the users with it. Also, the import feature was specially designed for cases like yours.
This is of no use to me, as the underlying xml-document may over time get additional nodes (e.g. "elem"-nodes).
I don't understand how this is problem, as you can simply import the file again when you change it. Also, if you create the file from scratch, as I understand you are doing now, you need to update it in the same way when a new node it added to the file.

Can you please post the .aip file on the forums or send it by e-mail at support at advancedinstaller dot com so we can understand better you settings?

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
aldebaran
Posts: 23
Joined: Wed Dec 05, 2007 4:04 pm
Location: Hannover, Germany
Contact: Website

Re: xml file substituting attribute value of wrong node

Hi Bogdan,

thanks for looking into this.
Bogdan wrote: We don't have any samples because the editor is quite straight forward, no major problems were encountered by the users with it. Also, the import feature was specially designed for cases like yours.
This is of no use to me, as the underlying xml-document may over time get additional nodes (e.g. "elem"-nodes).
I don't understand how this is problem, as you can simply import the file again when you change it. Also, if you create the file from scratch, as I understand you are doing now, you need to update it in the same way when a new node it added to the file.
Well, if I were to import the xml file every time an additional node, e.g. '<elem id="0">[...]</elem>' was inserted (at the beginning of the xml file), everything might work as You say. But of course just adding an xml-element ought not to make it necessary to update the aip file (at least as long as its contents need not to be configured thru ai, too). Usually we craft our aip files (using synchronized folders, exclude and import filters) with care and don't touch them for quite a while afterwards.

I was hoping marking an attribute as an "identifier" together with its expected value is sufficient to get a hold of a certain node, as illustrated in my initially posted example.
Bogdan wrote: Can you please post the .aip file on the forums or send it by e-mail at support at advancedinstaller dot com so we can understand better you settings?
Attached is an Advanced Installer 7.21 aip file hopefully illustrating my point. The idea was to start with a file a) and getting a file b) using my original posting as a reference.
Attachments
XmlSubst.aip
Sample ai project trying to modify a single xml file on deployment
(8.8 KiB) Downloaded 543 times
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: xml file substituting attribute value of wrong node

Hello,

The issue seems to be caused by changing the "on install" value for "elem":
Untitled.jpg
Untitled.jpg (46.16 KiB) Viewed 22461 times
We'll improve the option in the future to protect user settings that would lead to this behavior.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
aldebaran
Posts: 23
Joined: Wed Dec 05, 2007 4:04 pm
Location: Hannover, Germany
Contact: Website

Re: xml file substituting attribute value of wrong node

Regarding my submitted test project "XmlSubst.aip" I would like to confirm that checking the "on install" checkbox does indeed make the difference.

Not sure, whether You want to change the default behaviour (i.e. obeying the "on install" state of child nodes regardless of a the "on install" state of its parent [or ancestors?]) or improve the docs. One or the other is beneficial to the user.

Thanks a lot!
ic_j2
Posts: 1
Joined: Tue Aug 14, 2012 5:17 pm

Re: xml file substituting attribute value of wrong node

Hi

I have a similar issue, If we have an XML like this :

Code: Select all

<?xml version="1.0" standalone="yes"?>
<root>
  <elem id="elem1">
    <child value="origTest" />
     <child value="orig Value" />
  </elem>
</root>
Where the attribute "value" is my Identifier, and I want to look for "orig Value", instead of matching "orig Value" is matching "origTest", the issue is repeated on several nodes, it seems like is not taking into account the entire string "orig Value" only the first work "orig".
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: xml file substituting attribute value of wrong node

Hi,

Can you please send us the .AIP (project) file you are using to support at advancedinstaller dot com so we can take a look?

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
JPP
Posts: 18
Joined: Wed Oct 28, 2015 4:34 pm

Re: xml file substituting attribute value of wrong node

Bogdan wrote:We don't have any samples because the editor is quite straight forward, no major problems were encountered by the users with it. Also, the import feature was specially designed for cases like yours.
This is of no use to me, as the underlying xml-document may over time get additional nodes (e.g. "elem"-nodes).
I don't understand how this is problem, as you can simply import the file again when you change it. Also, if you create the file from scratch, as I understand you are doing now, you need to update it in the same way when a new node it added to the file.

Can you please post the .aip file on the forums or send it by e-mail at support at advancedinstaller dot com so we can understand better you settings?

Regards,
Bogdan
I know I am bringing an old message back but I found this while trying to find a solution to my problem. I have an xml file (web.config) that I've already imported into my project. The source xml file has been changed and I need to go edit some of the new elements. According to this suggestion we should simply be able to import the file again and get the changes? Is there a procedure to follow for this because whenever I try I get an error message saying "Failed to import the following project files and it lists the file that is already in the project. If I delete the file and reimport it then I will lose all the changes that I've already done and this is not something I really don't want.

I spoke to a colleague that also uses AI and he tells me that to do this he makes a backup of his project file, deletes the xml file, reimports it, and then merges the backup and new AIP files. I guess his xml files are smaller and simpler than mine because I tried this approach and found that it really wasn't a fun scenario. This is only the first time that one of the xml files gets modified but I think this is the maintenance part I will dread the most.
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: xml file substituting attribute value of wrong node

Hi,

Can you please tell me which XML file has been changed? The XML file that is already imported in the project or the XML file available on the machine?

If it is the XML file from the project, then, it will update the XML file from the machine when the package is installed. If it is the XML file from the machine, then you can simply re-import it to the project and it will replace the one that already exists in the project.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
JPP
Posts: 18
Joined: Wed Oct 28, 2015 4:34 pm

Re: xml file substituting attribute value of wrong node

Hello,

My project installs a few different websites. Each of these websites has a web.config xml file. When installing I have to change values for many different keys so I imported each of these web.config files into my project and applied the necessary modifications. Everything works perfectly, whenever I build my project it takes the existing web.config files and when installing it modifies the proper value according to where it is being installed and a few user inputs.

A few weeks later some elements are added to the web.config files, if I didn't need to modify these new values during install time I could change nothing to my project, simply rebuild it and everything would work perfectly. My issue is that I need to modify some of these new keys duing the install process so I would need to either re-import the xml file or manually add each new elements into the xml editor. There weren't that many elements added this time so I could could it manually but I don't know if it will always be only small modifications.

When you say you can re-import the file, do I need to delete the old one from the project first? If I do this, I lose all modifications I've done to it. If I don't delete the file beforehand I get an error message saying that the file already exists in the project, is there another way to do this?
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: xml file substituting attribute value of wrong node

Hi,

As I understand, you want to merge the XML file from the machine with the XML file available in the project. However, I'm afraid that this is not possible. The XML file from the project can only be replaced/overwritten with a file from the machine.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”