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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|