Attached are two screen shots, and my code. I am trying to get the animation_sequence as a closing and ending bracket, I’ve tried my best but now I seek your help. Here is my attempt, I decided to do this, but now my state, as in “Yahoo” appears as “Yahoo “, I know it might have to do with the setTextContent of animation sequence(although I don’t understand how that can add spaces to my state content. My problem here is that all I wanted was my animation sequence to have closing and ending brackets. I resolved by looking for two extra spaces in my if statement, but I feel like that’s a pathetic approach, and its kind of like accepting defeat.
The second image I attached, is what I wish to achieve, without adding extra ” ” to my state. Without my code below(the set text content part in specific)it produces image one. Just when I thought I solved it, these two spaces are killing me. If you need any extra code, please let me know. I need your help.
Element animationState = testDoc.createElement("animation_state");
Element sequence = testDoc.createElement("animation_sequence");
sequence.setTextContent(" ");
sequence.appendChild(testDoc.createTextNode(" "));
testDoc.getElementsByTagName("animations_list").item(0).appendChild(animationState).appendChild(state);
testDoc.getElementsByTagName("animation_state").item(testDoc.getElementsByTagName("state").getLength() - 1).appendChild(sequence);
for(int i = 0; i<testDoc.getElementsByTagName("animation_state").getLength(); i++)
{
if( testDoc.getElementsByTagName("animation_state").item(i).getTextContent().
equals(Poseur.getPoseur().getAnimatedSpriteViewer().getSpriteStateComboBox().
getSelectedItem().toString())||(testDoc.getElementsByTagName("animation_state").item(i).getTextContent()).equals(Poseur.getPoseur().getAnimatedSpriteViewer().getSpriteStateComboBox().getSelectedItem().toString()+" "))
{
testDoc.getElementsByTagName("animation_sequence").item(i).appendChild(poseImage);
}
}


At the point you are creating the
animation_sequencenode, in Java it appears, you are working in an abstract tree structure. At this point, there’s no such thing as opening or closing tags, just nodes.The existence of “tags” (opening and closing) at all is a facet of the XML document’s serialization, i.e. how it is converted into a textual form for output. As far as the standard goes, the serialization
<animation_sequence/>is indistinguishable from<animation_sequence></animation_sequence>, so a serializer is allowed to write either one.Some serializers will allow you to specify how you want empty nodes written out, either in shorthand form (trailing
/) or as opening/closing tag pairs. You will need to research your particular XML library and determine if the serializer provides such an option.