🦉 🎤   RapidMiner Wisdom 2020 - CALL FOR SPEAKERS   🦉 🎤

We are inviting all community members to submit proposals to speak at Wisdom 2020 in Boston.

Whether it's a cool RapidMiner trick or a use case implementation, we want to see what you have.
Form link is below and deadline for submissions is November 15. See you in Boston!


Read and modify XML file with execute script operator

AleAle Member Posts: 6 Contributor I
edited November 2018 in Help
I'm trying to read an xml file without using the ReadXml operator. I want to treat is as a text file and then extract some values from it. I was wondering if this can be done using the execute script operator. This is part of the java code I'm using with the execute script operator. I don't get any error but it's like it doesn't even start the execution.

String path="/home/myFolder/file.xml";
String content = new Scanner(new File(path)).useDelimiter("\\Z").next();
//some operations on content
return content;
Would you suggest a better way to do this?
Thanks a lot.



  • Marco_BoeckMarco_Boeck Team Lead Software Engineering Administrator, Moderator, Employee, Member, University Professor Posts: 1,810   RM Engineering

    this will read a file line by line and create a document. To use the output, you need to create an instance of an IOObject and return that.

    import com.rapidminer.operator.text.Document;
    import com.rapidminer.operator.text.Token;

    import java.util.List;
    import java.util.LinkedList;
    import java.util.Scanner;
    import java.nio.file.Paths;

    String pathToFile = 'C:/users/boeck/Desktop/test.txt';
    Scanner content = new Scanner(Paths.get(pathToFile).toFile());

    List<Token> newTokens = new LinkedList<>();
    while (content.hasNextLine()) {
    newTokens.add(new Token(content.nextLine(), 1.0f));

    return new Document(newTokens);
  • AleAle Member Posts: 6 Contributor I
    Thank you very much. It's very helpful
Sign In or Register to comment.