Removing characters from an Element Text

In my program I extract text from one of the element in my xml document and I need to change the root element of the xml document to the text that I’ve extracted from one of the element in the doc

 

Element rootElement = (Element) xmlObject.getElement();

Element element= rootElement.getChild("Element");

String text= element.getText();

rootElement.setName(text);



I get an error [I]The name “Internal Training”(which is the text returned) is not legal for JDOM/XML elements: XML names cannot contain the character " "

How do I remove the characters “”.

Hello venuela,

how about the following, to change the space characters to underscores?

   String text= element.getText();
   String elementName = text.replace(' ', '_');
   rootElement.setName(elementName);


You could also use the replaceAll(String regex, String replacement) method in the String class to do something more complex, if required.

Greetings,
Trevor.