Question: well, i'm new in this and i dont know how i can make this program works, i need Write a program that calculates and returns the sum of the components of a vector squared

and i got this error:

```
import java.util.*;
public class cuadrado
{

    public static void main(String[] args) 
    {   
        Scanner teclado= new Scanner (System.in);
        int n=0,i=0,y=0;       

        System.out.println("ingrese el valor de el vector");

        n=teclado.nextInt();

        int[ ]suma=new int[n];

        for(i=0;i<suma.lenght;i=i+1);
        {
            System.out.println("ingrese el valor de un numero");
            suma[i]=teclado.nextInt();
            y+=suma[i];
            System.out.println(""+y);         

        }

    }
}

```

cannot find symbol in the line 16

Answer: 
It's fairly simple to do this with XML::Twig (and I am happy I got the "delete the current element during parsing" to work a while back):

```
#!/usr/bin/perl

use strict;
use warnings;

use XML::Twig;

my $delt= 'delt.xml';

XML::Twig->new( twig_handlers => { delt => \&delt },
                pretty_print => 'indented',
              )
          ->parsefile( $delt);

exit;

sub delt
  { my( $t, $delt)= @_;

    my $delt_file= sprintf( 'delt_%s.xml', $delt->id);

    # the only tricky part: remove previous doc if needed
    if( my $prev_doc= $delt->parent( 'doc')->prev_sibling( 'doc')) 
      { $prev_doc->delete; }

    $t->print_to_file( $delt_file);

    $delt->delete;
  }

```
The reason you're having difficult is because what you're doing is extracting a subset from an XML doc, but then trying to also include some of the stuff from the 'parent'. 

Pulling your 'delts' out would be fairly straightforward 

I would be wanting to use `XML::Twig` with this - this is a perfect place to use a twig handler. 

I'd be thinking *something* along the lines of (and apologies, this doesn't quite work yet). 

```
use strict;
use warnings;
use XML::Twig;

sub process_delt {
    my ( $twig, $delt ) = @_;
    my $delt_id = $delt->att('id');
    print "\nID:\n$delt_id\n";
    my $filename = "$delt_id.xml";

    $delt->set_pretty_print('indented');
    $delt->print;

    print "\n--------\n";

}

my $twig = XML::Twig->new(
    twig_handlers => { delt => \&process_delt },
);
local $/;
$twig->parse(<DATA>);

__DATA__
<xml>
<service>
<title>split xml</title>
<main>
<doc id="001">
<title>doc1</title>
<delt id="0001">
<title>delt1</title>
<text>num1</text>``
<text>num1</text>
</delt>
<delt id="0002-A">
<title>delt1</title>
<text>num1</text>
<text>num1</text>
</delt>
</doc>
<doc id="002">
<title>doc2</title>
<delt id="0003">
<title>delt1</title>
<text>num1</text>
<text>num1</text>
</delt>
<delt id="0004">
<title>delt1</title>
<text>num1</text>
<text>num1</text>
</delt>
</doc>
</main>
</service>
</xml>

```

Edit: Take a look at @mirod's answer, because it's fully working. This one will just extract each 'delt' and then you'd probably have to mess around with figuring out parent stuff.