Carter, you didn't say what you wanted to add, and where. I'll make the
assumption you want to add a sibling <patch> node to release version 2.0.
Here are a few options:

----OPTION 1----
Take another look at XML::Simple. I don't see anything in your XML that
wouldn't be possible to create using XML::Simple. Did you use the KeyAttr
and ForceArray options?

With your sample XML, the following code:

  use XML::Simple;
  my $xs = XML::Simple->new(KeepRoot=>1, ForceArray=>1, KeyAttr=>[]);
  my $ref = $xs->XMLin($xml);
  print $xs->XMLout($ref);

reads it in and prints an XML document equivalent to the input.

----OPTION 2----
If you're comfortable with OO, and maybe a little adventurous, you may want
to look at the new module Class::XML. This is supposed to allow you to treat
your XML as objects. You do some upfront work including creating a couple
small packages representing your XML constructs (Patch and ProductRelease).
If you also add a "relation" called get_release, adding a patch might be
something like this (completely untested code from a skim of the
docs--consider it pseudocode):

  my $new_patch = Patch->new;
  $new_patch->number(2);
  $new_patch->readme('readme-2.txt');
  $new_patch->file('patchfile.gz');
  $new_patch->desc('Description');
  
  my ($latest_release) = ProductRelease->get_release("2.0");
  $latest_release->patch($new_patch);

----OPTION 3----
DOM's not hard when you are very familiar with the structure of the XML.
Here's sample XML::LibXML code that adds a new <patch> to release 2.0
(tested).

use XML::LibXML;
my $patches = XML::LibXML->new->parse_file('patches.xml');
my ($release) = $patches->findnodes('//[EMAIL PROTECTED]"2.0"]');

my $new_patch= XML::LibXML::Element->new('patch');
$new_patch->appendTextChild('number','2');
$new_patch->appendTextChild('readme','readme-2.txt');
$new_patch->appendTextChild('file','patchfile.gz');
$new_patch->appendTextChild('desc','Description');

my ($release) = $patches->findnodes('//product-release[version="2.0"]');
$release->appendChild($new_patch);

print $patches->toString(1); #or $patches->toFile($filename);


-- 
Mark Thomas                    [EMAIL PROTECTED] 
Internet Systems Architect     DigitalNet, Inc. 

$_=q;KvtuyboopuifeyQQfeemyibdlfee;; y.e.s. ;y+B-x+A-w+s; ;y;y; ;;print;; 
  

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to