xml file
<?xml version="1.0" encoding="UTF-8" standalone="no"?><movies>
<movie id="1111">
<title>Blackhat</title>
<genre>thriller</genre>
<duration> 90 mins </duration>
<age>28</age></movie>
<movie id="1002">
<title>The Wedding Ringer</title>
<genre>comedy</genre>
<duration> 100 mins </duration>
</movie>
<movie id="1003">
<title>The Avengers</title>
<genre>action</genre>
<duration> 180 mins </duration>
</movie>
<movie id="1004">
<title>Taken 3</title>
<genre>action</genre>
<duration> 100 mins </duration>
</movie>
<movie id="1005">
<title>Insurgent</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
</movie>
<movie id="1006">
<title>Jurassic World</title>
<genre>Adventure</genre>
<duration>120 mins</duration>
</movie>
<movie id="1111">
<title>Interstellar</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
</movie>
</movies>
what i want to adding movie id tag to the last line, for example
<?xml version="1.0" encoding="UTF-8" standalone="no"?><movies>
<movie id="1111">
<title>Blackhat</title>
<genre>thriller</genre>
<duration> 90 mins </duration>
<age>28</age></movie>
<movie id="1002">
<title>The Wedding Ringer</title>
<genre>comedy</genre>
<duration> 100 mins </duration>
</movie>
<movie id="1003">
<title>The Avengers</title>
<genre>action</genre>
<duration> 180 mins </duration>
</movie>
<movie id="1004">
<title>Taken 3</title>
<genre>action</genre>
<duration> 100 mins </duration>
</movie>
<movie id="1005">
<title>Insurgent</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
</movie>
<movie id="1006">
<title>Jurassic World</title>
<genre>Adventure</genre>
<duration>120 mins</duration>
</movie>
<movie id="1111">
<title>Interstellar</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
</movie>
**<movie id="2222">
<title>test</title>
<genre>test</genre>
<duration>test</duration>
</movie>**
</movies>
i try to use
NodeList nodes = doc.getElementsByTagName("movie");
for (int temp = 0; temp < nodes.getLength(); temp++){
Element element = (Element) doc.getElementsByTagName("movie").item(temp+1);
element.setAttribute("id", "2222");
to create and insert the attribute into last line but the
.getElementsByTagName("movie").item(temp+1);
only work with existing attribute().