RE: Edit and Existing XML
Dale Puckett <[email protected]> Tue, 10 Sep 2013 19:04:11 +0000
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <56B4BC5D7572F448831D1681DB344A9B8918B1DE@BW-Exchange01.brainworks.local> |
I use the XML::Writer module.
use XML::Writer;
Then you can use something simple like:
$writer->dataElement("key1", $value1);
For each node.
Dale
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Tuesday, September 10, 2013 2:00 PM
To: [email protected]
Subject: Perl-XML Digest, Vol 108, Issue 2
Send Perl-XML mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://listserv.ActiveState.com/mailman/listinfo/perl-xml
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific than "Re: Contents of Perl-XML digest..."
Today's Topics:
1. edit an existing XML (Lis Maria)
2. Re: edit an existing XML (Francisco Obispo)
3. Re: edit an existing XML (Michael Ludwig)
4. Re: edit an existing XML (Paul Robert Marino)
----------------------------------------------------------------------
Message: 1
Date: Tue, 10 Sep 2013 11:51:30 +0530
From: Lis Maria <[email protected]>
Subject: edit an existing XML
To: [email protected]
Message-ID:
<CAC=vZ7ENhroLvc3k70O3L88VMrf059L9B5cSQyX2K=2mgqJdEg@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I am new to perl, and the task i have is to read a config file to get the values of certain keys and insert this value into an existing xml.
Example :
Config.properties
----------------------------
key1=value1
config.xml
-----------------------------
<key1></key1>
The perl script should be able to insert the value 'value1' into the <key1> tag. Can someone suggest the perl module which i can use for achieving the same.
Thanks,
Lis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.ActiveState.com/pipermail/perl-xml/attachments/20130910/230f28e4/attachment-0001.html
------------------------------
Message: 2
Date: Tue, 10 Sep 2013 00:02:49 -0700
From: Francisco Obispo <[email protected]>
Subject: Re: edit an existing XML
To: Lis Maria <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
I prefer to use XML::LibXML for pretty much everything I do.
On Sep 9, 2013, at 11:21 PM, Lis Maria <[email protected]> wrote:
> Hi,
>
> I am new to perl, and the task i have is to read a config file to get the values of certain keys and insert this value into an existing xml.
>
> Example :
>
> Config.properties
> ----------------------------
> key1=value1
>
>
> config.xml
> -----------------------------
> <key1></key1>
>
>
> The perl script should be able to insert the value 'value1' into the <key1> tag. Can someone suggest the perl module which i can use for achieving the same.
>
> Thanks,
> Lis
> _______________________________________________
> Perl-XML mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Francisco Obispo
email: [email protected]
Phone: +1 650 423 1374 || INOC-DBA *3557* NOC PGP KeyID = B38DB1BE
------------------------------
Message: 3
Date: Tue, 10 Sep 2013 11:09:21 +0200
From: Michael Ludwig <[email protected]>
Subject: Re: edit an existing XML
To: [email protected]
Message-ID: <20130910090921.GB7668@Dago>
Content-Type: text/plain; charset=us-ascii
Lis Maria schrieb am 10.09.2013 um 11:51 (+0530):
> I am new to perl, and the task i have is to read a config file to get
> the values of certain keys and insert this value into an existing xml.
>
> Example :
>
> Config.properties
> ----------------------------
> key1=value1
>
>
> config.xml
> -----------------------------
> <key1></key1>
>
>
> The perl script should be able to insert the value 'value1' into the
> <key1> tag. Can someone suggest the perl module which i can use for
> achieving the same.
Go with XML::LibXML. Note it offers various interfaces for dealing with
XML. Use the DOM interface and go looking for getElementsByTagName to
find the element node (key1), and probably replaceChild like this:
use strict;
use warnings;
use XML::LibXML;
my $parser = XML::LibXML->new;
my $dom = $parser->load_xml(string =>
'<root><elm1>eins</elm1><elm2/></root>');
print $dom->toString(1);
my($elm) = $dom->getElementsByTagName('elm1');
my $txt = $elm->firstChild or die 'element node not found';
my $new = $dom->createTextNode('zwei');
$elm->replaceChild($new, $txt);
print $dom->toString(1);
Michael
------------------------------
Message: 4
Date: Tue, 10 Sep 2013 08:02:50 -0400
From: "Paul Robert Marino" <[email protected]>
Subject: Re: edit an existing XML
To: "Lis Maria" <[email protected]>,
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL: http://listserv.ActiveState.com/pipermail/perl-xml/attachments/20130910/9ddefa82/attachment-0001.html
------------------------------
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
End of Perl-XML Digest, Vol 108, Issue 2
****************************************
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs