Good day Monks!
I have a config xml file that I actually created with the xml lib so I know it's valid ;-) It is nicely formatted with nice indents etc as toString(1) does so well.
I wanted to add an entry to it so I parsed it in, added to it and saved it again with toString(1)... Oddly the elements we all on one line and not pretty like the rest of the document. Here is a brief example.
my ($configuri) = $basepath."config.xml";
my $cparser = XML::LibXML->new();
# load config file
my $config = $cparser->parse_file($configuri);
# then an xpath to get to where I want to be
foreach my $xsites ($lrconfig->findnodes("//linkrabbitconfig/sites"))
{
$xnewsite = $config->createElement('site');
$xsites->appendChild($xnewsite);
$xsitename = $config->createElement('sitename');
$xnewsite->addChild($xsitename);
$xsitename->addChild( $config->createCDATASection($args{'site'}) )
+;
# add a bunch more elements
}
# output xml file
open (XMLfile,">".$configuri);
binmode(XMLfile,":utf8");
autoflush XMLfile 1;
chmod 0664, $outfile;
# dump the xml document to file
print XMLfile $config->toString(1);
close(XMLfile);
Any help would be very much appreciated, I am thinking that it might have a something to do with a xml object and a dom object? Am I close?
Thank you in advance!
Scott
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.