use XML::DOM;

my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ("domeinfuehrung.xml");
my $outdoc = $parser->parse ('<?xml version="1.0" encoding="iso-8859-1" ?><ausgabe/>');

my $nodes = $doc->getElementsByTagName ("h");
my $n = $nodes->getLength;

for (my $i = 0; $i < $n; $i++) {
	my $node = $nodes->item ($i)->cloneNode(TRUE);
	$node->setOwnerDocument($outdoc);
	my $att = $outdoc->createAttribute("id");
	$att->setValue("chapter" . ($i+1));
	$node->setAttributeNode($att);
	$outdoc->getDocumentElement->appendChild($node);
}

$outdoc->printToFile("out.xml");