Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Result (partial):my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($file); $root = $doc->documentElement(); $cdoc = $doc->getElementsById($docname); open(FH, ">", $file) or die "Open file '$tracefile' failed: $!\n"; flock(FH, LOCK_SH); seek(FH, 0, SEEK_SET); for my $para ($document->getElementsByTagName ("p")){ my $status = processing($para); my @paras = $root->getElementsByTagName('sentence'); my $exist_para = $root->getElementsById($para->getAttribute("i +d")); my $para_elem; if(!defined($exist_para)){ $para_elem = $root->createElement('sentence'); $para_elem->setAttribute('xml:id', $para->getAttribute("id +")); $para_elem->setAttribute('index', scalar(@paras)); }else{ $para_elem = $exist_para; } if($status == 1){ $para_elem->setAttribute('class', 'problem'); }elsif($status == 0){ $para_elem->setAttribute('class', 'fine'); }else{ $para_elem->setAttribute('class', 'skip'); } $cdoc->appendChild($para_elem); }
The index here shown I get some trouble that the element is not written out while I am processing (seems instead of write out the element string, it print a newline only)....and they are really missing when I compare the log on the screen. It appear in both case that I write the file at once or parse/write repeatedly. Any Idea?<document src="0.xml" xml:id="0.xml" index="0"> <sentence xml:id="0_xml0002" index="0"/> </document> <document src="10.xml" xml:id="10.xml" index="1"> </document> <document src="16.xml" xml:id="16.xml" index="3"> <sentence xml:id="16xml_0008" index="2"/> </document>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Element Missing in output XML file?
by roboticus (Chancellor) on Mar 11, 2008 at 11:41 UTC | |
by Anonymous Monk on Mar 11, 2008 at 17:25 UTC | |
by roboticus (Chancellor) on Mar 12, 2008 at 03:49 UTC | |
by Anonymous Monk on Mar 12, 2008 at 07:12 UTC |