Here is what I have
<animation_state> <state>run</state> <animation_sequence> <pose duration="10" image_id="1"/> <pose duration="10" image_id="2"/> <pose duration="10" image_id="3"/> </animation_sequence>
I would like to give the user the ability to move a specific image up and down, however, since they are stored in XML, this means that I need to change the identifiers of the images around. Assuming the user wants image_id = 3 to be first in the sequence or in the middle, or anywhere depending on his needs, how can I manipulate XML? I am using the DOM.
If the user wants image 3 to be the first, my XML should look like this:
<animation_state> <state>run</state> <animation_sequence> <pose duration="10" image_id="3"/> <pose duration="10" image_id="1"/> <pose duration="10" image_id="2"/> </animation_sequence>
My attempt:
Document dom = parser.getDocument(); for (int i = 0; i < dom.getElementsByTagName("animation_state").getLength(); i++) { if (dom.getElementsByTagName("animation_state").item(i).getChildNodes().item(0).getTextContent().equalsIgnoreCase(target)) { posVal = i; } } NodeList list = dom.getElementsByTagName("animation_sequence").item(posVal).getChildNodes(); for(int b=0; b<list.getLength(); b++) { if(list.item(b).getAttributes().item(1).getNodeValue().equalsIgnoreCase(PoseSelectionListener.imageIDOfSelectedPose)) { Node toBeMoved = list.item(b); dom.getElementsByTagName("animation_sequence").item(posVal).appendChild(toBeMoved); System.out.println(toBeMoved.getAttributes().item(0).getNodeName()); } }
source share