1828677 Members
2278 Online
109984 Solutions
New Discussion

Update XML File

 
Allanm
Super Advisor

Update XML File


We have a certain set of tools in production that need to be access controlled through an xml file.

The format of the xml file is attached and I need a way to automate the update to this xml file when a user needs to be added and removed.

There are some 15 tools and the scenarios to consider here while adding a user is that -

1) User that needs a limited set of access to a few tools and not all.
2) Super user with all the access (*)

Thanks,
Allan
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: Update XML File

Hi Allan:

> I need a way to automate the update to this xml file when a user needs to be added and removed.

And so what do you want updated and/or deleted? Do we presume the '
Regards!

...JRF...
Allanm
Super Advisor

Re: Update XML File

Yes that's correct JRF!

Regards,
Allan.
James R. Ferguson
Acclaimed Contributor

Re: Update XML File

Hi Allan:

I would certainly use Perl. CPAN has a number of XML parsing modules to do the heavy lifting.

Regards!

...JRF...
Allanm
Super Advisor

Re: Update XML File

JRF, I don't know Perl , can you make a script using Perl ?

Thanks,
Allan
Allanm
Super Advisor

Re: Update XML File

JRF ,

I figured a way to design this and implement in bash ...

Plan to have a few intermediate files before the actual xml is uploaded.

One of the intermediate files would be a xml template file which has the required XML for adding a user. This template file would have sample data which would be replaced by "sed -e" and populated to a txt file and appended to the target xml access file.

James R. Ferguson
Acclaimed Contributor

Re: Update XML File

Hi Allan:

> I figured a way to design this and implement in bash ...Plan to have a few intermediate files before the actual xml is uploaded. One of the intermediate files would be a xml template file which has the required XML for adding a user. This template file would have sample data which would be replaced by "sed -e" and populated to a txt file and appended to the target xml access file.

That sounds like a viable solution.

Regards!

...JRF...
Allanm
Super Advisor

Re: Update XML File

Hi JRF/All,

I was able to make the script and got it working, Can you review it and suggest any improvements in coding.

I am not very happy with the multiple sed's, can you modify in someway so that I can avoid multiple sed's.

Attaching the script for your perusal.

Thanks,
Allan
Allanm
Super Advisor

Re: Update XML File

The other thing that bothers me is that I am solving for adding one user only-

Currently this is how it works

1) Gets the user that needs to be added along with the tools that he will have access to from a file(1).(wget and get the file1)

2) I replace the values in a template file(2) ( which is currently has fields for one user only) with the values from file(1) and generate a append file(3).

3)The append-file is appended to the target xml file(4).


This solves for adding a user but not for deleting or any other scenario - lets say a user who is already added needs access to few more tools or he needs to be deleted.



My question is how can I make changes to make current script so that if I get file(1) with multiple users it can handle that and generates a brand new XML file instead of appending it.