CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Add element in XML file

 



Andryx92
New User

Feb 22, 2014, 6:33 AM

Post #1 of 3 (1012 views)
Add element in XML file Can't Post

I apologize in advance if I do not speak good English but i am an Italian student...
My problem is:
I want to insert a new element (new admin) in a XML file and save the update. For example I want start whit this element:

<admins>
<admin>
<mail>admin@admin.it</mail>
<password>admin</password>
<user>admin</user>
</admin>
</admins>

the output tha i want is for esample:
<admins>
<admin>
<mail>admin@admin.it</mail>
<password>admin</password>
<user>admin</user>
</admin>
<admin>
<mail>master@uni.it</mail>
<password>master</password>
<user>master</user>
</admin>
</admins>

How i can do it?

Thanks and sorry for the bad english!


(This post was edited by Andryx92 on Feb 22, 2014, 6:41 AM)


Laurent_R
Veteran / Moderator

Feb 22, 2014, 9:03 AM

Post #2 of 3 (1000 views)
Re: [Andryx92] Add element in XML file [In reply to] Can't Post

First, many people on this forum and on many English-language forums in general have a mother tongue that is not English, I don't think any one will make a big deal about it. Just make your best to be understood, but don't worry too much about using the exact correct syntax, you're not the only one in this case (starting with me).

Now, to your question: although there are some ways around it, it is in general not possible to modify an existing free-format file. The way to modify a file is generally to create a new amended file and then to replace the old file with the new one.


BillKSmith
Veteran

Feb 22, 2014, 8:29 PM

Post #3 of 3 (979 views)
Re: [Andryx92] Add element in XML file [In reply to] Can't Post

When you follow Laurent's plan, you have to make the actual edits in memory. Your example is simple enough to do this with a regular expression. The problem is that the syntax of html can be to complex to edit this way. You will probably have to search CPAN for a module to parse your html correctly.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives