I am trying to take user input from a console and feed that into a XML file. Evrytime the user moves on to the next line I want to take the string they typed in and create a new element. Here is what I am trying to achieve:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<note>
<header>
<Tempo Laya="2"/>
</header>
<Notes>
<n1 Bol="Text the user entered"/>
<n2 Bol="Text the user entered over the next iteration"/>
<n3 Bol="Text the user entered over the next iteration"/>
</Notes>
</note>
I thought the best way to do this would be to create these elements, however; I am not able to create unique element names through this. Here is my code so far:
//Create note element
Element notes = doc.createElement("Notes");
rootElement.appendChild(notes);
System.out.println("Input your notes matraa by maatra. To proceed to the next maatra press ENTER. \n To exit enter END");
do{
int noteCount = 1;
System.out.println("Maatra: ");
bol = scanner.nextLine();
}while(scanner.nextLine()!= "END");
Is there any way to create and append the elements using the loop above. If not how else could I do it?