IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Removing characters from an Element Text

  • 1.  Removing characters from an Element Text

    Posted Fri November 14, 2003 12:36 PM

    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 “”.


    #API-Management
    #webMethods-Tamino-XML-Server-APIs
    #webMethods


  • 2.  RE: Removing characters from an Element Text

    Posted Fri November 14, 2003 07:12 PM

    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.


    #webMethods-Tamino-XML-Server-APIs
    #webMethods
    #API-Management