chenino has asked for the wisdom of the Perl Monks concerning the following question:

Hey Folks and at first Hi there, I am pretty new to Perl and have somehow managed to get around with it (also thanks to you).

My actual Problem at the time is, i have to generate and edit some XML. I used XML::Twig up to now, but in my current Project i am forced to use XML::LibXML and XML::Compile. XML::Compile::Cache is not there for use.

So far i used XML::Compile::Schema, as an .xsd was given to me. My Problem now is, after generating the file for the first time and saving everything, I have to update it with some entries lateron. I can't find methods for this in the Doc and so i am asking for your whisdom.

Replies are listed 'Best First'.
Re: Edit XML through XML Compile
by Anonymous Monk on Dec 19, 2014 at 15:49 UTC
      Well i know generally a code example is helpfull, but i thought in this case its a pretty General question. Anyhow, I will give you some examples of what i am doing at the Moment. given is a Schema like :
      -data -properties (List of properties in here) -suites -tests
      Up to now i got my code writing the properties.
      $schema->template('PERL', $type); #warn $schema->template('PERL', $type); my $doc = XML::LibXML::Document->new('1.0', 'UTF-8'); my $write = $schema->compile(WRITER => $type, use_default_namespace +=> 1); my %hash; #some filling of the hash with values my $xml = $write->($doc, $hash); $doc->setDocumentElement($xml);
      So the first part of my XML File is generated. Later on, in a completely different part of the program, tests have to be written into the second section. Those tests have to comply the Schema in the xsd file. So i have to reopen the saved XML file from the code above and insert some new tags in it, at specific Points (every test has to go into a specific Suite, so there is more than one Suite) Writing a new hash and doing
      my $xml = $write->($doc, $hash); $doc->setDocumentElement($xml);
      again, does not work out. I need to reopen, search a node and insert children. This was easy possible with XML Twig, but as said i can only use above mentioned packages. Was this enough code or do you Need more explaning?