Remove XML file element

Got a problem you cannot solve? Try here.
tzachk
Posts: 171
Joined: Wed Jul 18, 2012 12:14 am

Remove XML file element

Postby tzachk » Tue Apr 29, 2014 3:49 am

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.

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Remove XML file element

Postby FrancescoT » Tue Apr 29, 2014 11:28 am

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
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

tzachk
Posts: 171
Joined: Wed Jul 18, 2012 12:14 am

Re: Remove XML file element

Postby tzachk » Sun May 04, 2014 12:42 am

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

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Remove XML file element

Postby FrancescoT » Thu May 08, 2014 3:57 am

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
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

tzachk
Posts: 171
Joined: Wed Jul 18, 2012 12:14 am

Re: Remove XML file element

Postby tzachk » Tue May 13, 2014 5:27 am

Hi Francesco.

This issue needs to be resolved as it prevents altering XML files properly.

Regards,
Tzach


Return to “Technical Support”

Who is online

Users browsing this forum: Baidu [Spider] and 109 guests