|Do you know where your variables are?|
XML round-trip with comments and prologby pryrt (Abbot)
|on Jul 28, 2021 at 15:40 UTC||Need Help??|
pryrt has asked for the wisdom of the Perl Monks concerning the following question:
I want to automate changing some settings in an app which uses XML config files, but I am not an XML expert and don't have real experience with any of the XML modules (other than knowing from reading here that I need to avoid XML::Simple). I like starting from "known good" code as examples, and playing around until I understand it better. I found some of haukex's examples with XML::Rules, especially Re^6: XML compare with a key and Re: How do I get a list in a perl hash generated from an XML?, which got me to the point that I could get the XML parsed into an initial data structure which seems reasonable to me.
But my next goal was to round-trip the config file: to see if I could get an output file that's compatible with the input, so it's still usable as a config file for the app. So far, I've got a short example of:
... But there are two things I haven't figured out how to do, as evidenced by the differences between the input text and the output text.
So, is XML::Rules the right choice for this? (And if so, how do I accomplish it?) If not, which module is better equipped for my goals? (And could you provide a similar example, showing how to round-trip through the data structure and still have prolog and comments?)
edit: fixed missing sentence separator and missing paragraph indicators; fix title