Page 1 of 1
Remove XML file element
Posted: Tue Apr 29, 2014 3:49 am
by tzachk
Hi,
I have an XML file with a simple structure:
<xml>
<test>
<user>John</user>
<id>1</id>
</test>
</xml>
I would like to remove the whole id element from the xml leaving it in the following format.
<xml>
<test>
<user>John</user>
</test>
</xml>
How can I achieve this?
Regards,
T.
Re: Remove XML file element
Posted: Tue Apr 29, 2014 11:28 am
by FrancescoT
Dear tzachk,
supposing you have;
Code: Select all
<ApplicationSettings>
<Section Name="General">
<Key Name="RootPath" Value="C:\mytest\sales" />
<Key Name="Images" Value="\Jpg\" />
</Section>
<Section Name="Connection">
<Key Name="Server" Value="SERVER04" />
<Key Name="SqlDatabase" Value="PM4Uster" />
<Key Name="TrustedConnection" Value="0" />
</Section>
<Section Name="Agent">
<Key Name="UseAgent" Value="0" />
</Section>
<Users>
<key id="1" />
</Users>
</ApplicationSettings>
To remove all <Section Name="Connection"> elements, you should use;
Code: Select all
~InstallAware Clipboard Data~
~Edit XML File~
~{EB2F4EE3-D72D-46C3-A979-968DE0451E21}~
~C:\XMLFile2.xml~
~UTF-8~
~0~
~ApplicationSettings\Section~
~~
~"Name,Connection"~
~3~
~FALSE~
~FALSE~
~TRUE~
To remove all <Users> elements, you should use;
Code: Select all
~InstallAware Clipboard Data~
~Edit XML File~
~{7CB09363-E6EC-4173-8EB1-3FDF97531DA9}~
~C:\XMLFile2.xml~
~UTF-8~
~0~
~ApplicationSettings\Users~
~~
~~
~3~
~TRUE~
~FALSE~
~TRUE~
Hope this helps you.
Regards
Re: Remove XML file element
Posted: Sun May 04, 2014 12:42 am
by tzachk
Hi Francesco,
Thanks for your reply. I already tried it but it doesn't work for me. I did some testing and found out that my issue happens because of a minus character '-' between elements.
I've included your xml schema while changeing the value in the key element under Users.
Try the following to replicate:
Code: Select all
<ApplicationSettings>
<Section Name="General">
<Key Name="RootPath" Value="C:\mytest\sales"/>
<Key Name="Images" Value="\Jpg\"/>
</Section>
<Section Name="Connection">
<Key Name="Server" Value="SERVER04"/>
<Key Name="SqlDatabase" Value="PM4Uster"/>
<Key Name="TrustedConnection" Value="0"/>
</Section>
<Section Name="Agent">
<Key Name="UseAgent" Value="0"/>
</Section>
<Users>
<key>-</key>
</Users>
</ApplicationSettings>
Try to remove the ApplicationSettings\Users element. It shall fail. I tested this xml schema against w3 validator and it passes.
Please let me know what can be done.
Tzach
Re: Remove XML file element
Posted: Thu May 08, 2014 3:57 am
by FrancescoT
Dear Tzach,
unfortunately, our command can't be used with that element ... you may try to read the entire XML file using "Read from Text File" and then, to parse its content in order to remove that element. Finally you can save it using "Write to Text File" command.
Hope this helps you.
Regards
Re: Remove XML file element
Posted: Tue May 13, 2014 5:27 am
by tzachk
Hi Francesco.
This issue needs to be resolved as it prevents altering XML files properly.
Regards,
Tzach