I have a XML file like the following.
<?xml version="1.0" encoding="UTF-8"?>
<Site>
<Name>MySite</Name>
<Groups>
<Default></Default>
<GroupA></GroupA>
</Groups>
</Site>
I want to get all names of Groups' children elements (in this example 'Default' and 'GroupA') as a list of strings. I was trying the following.
public List<String> getGroupNames() {
List<String> names = new ArrayList<String>();
XPathExpression<Text> xpath = XPathFactory.instance().compile(
"/Site/Groups/*/name()", Filters.text());
List<Text> elements = xpath.evaluate(document);
if (elements.size() > 0) {
for (Text text : elements) {
names.add(text.getText());
}
return names;
}
return null;
}
This fails hard with the following exception.
class org.jaxen.saxpath.XPathSyntaxException: /Site/Groups/*/name(): 20: Expected node-type
What is the proper syntax for that? I do not understand the exception.