-2

In perl, how to set a value to node in xml? I have searched metacpan and not found a module related to xml has a method do this.

melpomene
  • 84,125
  • 8
  • 85
  • 148
user2799433
  • 171
  • 11
  • There are perl modules like [XML::LibXML](https://metacpan.org/pod/XML::LibXML), [XML::Simple](https://metacpan.org/pod/XML::Simple) which can be used to implement this. – rprakash Sep 22 '19 at 17:14
  • And, [XML::Twig](https://metacpan.org/pod/XML::Twig) also, as commented in this [answer](https://stackoverflow.com/a/58051122/1338382) – rprakash Sep 22 '19 at 17:15
  • @rprakash Are there any sample code on these modules? – user2799433 Sep 22 '19 at 18:41
  • 1
    @rprakash, Don't recommend a module whose own documentation recommends against using it! [Why is XML::Simple "discouraged"?](https://stackoverflow.com/q/33267765/589924) – ikegami Sep 22 '19 at 21:32
  • In the DOM model, XML elements don't have a value; they have child nodes, which might be text nodes. Depending on the parser, you might have to remove the elements children, then append a text node. – ikegami Sep 22 '19 at 21:35
  • @user2799433 XML::LibXML can be seen [here](https://grantm.github.io/perl-libxml-by-example/basics.html) – rprakash Sep 23 '19 at 06:26
  • @ikegami wasn't aware about the fact that XML::Simple is discouraged in new code. – rprakash Sep 23 '19 at 06:28
  • [XML::LibXML replace element value](https://stackoverflow.com/q/8411684/589924) – ikegami Sep 23 '19 at 16:08

1 Answers1

1

XML::Twig can modify XML, as can many other modules. To say any more, you'd need to explicate your task.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • I am writing a simple perl program to set data into xml file, the data is specified from command line arguments of this program. – user2799433 Sep 22 '19 at 16:30
  • That doesn't really tell me anything more than your original question. This may help: https://stackoverflow.com/help/how-to-ask – brian d foy Sep 23 '19 at 17:32