import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
String[] paths = new String[] {
"",
"myElement",
"myElement<{myIndex}>",
"myElement[@myAttribute='0']",
"something/myElement<{myIndex}>/somethingElse",
"something/myElement[@myAttribute='0']/somethingElse",
"something/myElement1[@myAttribute1='0']/somethingElse1/myElement2[@myAttribute2='0']/somethingElse2"
};
for (String path : paths) {
String path2 = removeAttributesFromPath(path);
System.out.format("'%s' -> '%s'\n", path, path2);
}
}
private static String removeAttributesFromPath(String path) {
String[] pathSections = path.split("/");
for (int i = 0; i < pathSections.length; ++i) {
String pathSection = pathSections[i];
int j = pathSection.indexOf('[');
if (j > -1) {
pathSections[i] = pathSection.substring(0, j);
} else {
j = pathSection.indexOf('<');
if (j > -1) {
pathSections[i] = pathSection.substring(0, j);
}
}
}
return String.join("/", pathSections);
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: