James trevel
New Member
Here is what I have,\[code\]<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>\[/code\]I would like to give the user the ability to move a certain image up and down, however, since they are stored in XML, that implies I have to change the image ids around. If suppose the user wants the image_id = 3, to be the first in the sequence, or in the middle, or wherever depending on his needs, how can i manipulate the XML? I am using DOM.If the user wants image 3, to be the first, this is how my XML should appear:\[code\]<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>\[/code\]My attempt:\[code\]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()); }}\[/code\]