dlr bug
[mcs.git] / docs / ecma334 / gentoc.pl
blob95e8abfb7eabd0aa142d4489d42f3c00a10f3d25
1 #!/usr/bin/perl
3 use XML::LibXML;
5 $parser = new XML::LibXML;
7 opendir DIR, ".";
8 foreach $file (readdir(DIR)) {
9 if ($file !~ /([\d\.]+)\.xml/) { next; }
10 $sec = $1;
12 $xml = $parser->parse_file("$sec.xml");
13 $titles{$sec} = $xml->findvalue('/clause/@title');
15 if ($sec =~ /^([\d\.]+)\.(\d+)$/) {
16 $parent = $1;
17 $sub = $2;
18 } else {
19 $parent = "";
20 $sub = $sec;
23 $sections{$parent}[$sub-1] = $sec;
25 closedir DIR;
27 $doc = new XML::LibXML::Document;
28 $toc = $doc->createElement('toc');
29 $doc->setDocumentElement($toc);
31 AddChildren($toc, '');
33 print $doc->toString(1);
35 sub AddChildren {
36 my $x = $sections{$_[1]};
37 my @x = @{ $x };
38 foreach my $s (@x) {
39 my $n = $doc->createElement('node');
40 $n->setAttribute('number', $s);
41 $n->setAttribute('name', $titles{$s});
42 $_[0]->appendChild($n);
44 AddChildren($n, $s);