@anduril I have removed the old method readXmlByXpath. Introduced XmlApi class to address xml stuff.
mcApi.xml().read(uri, xpath) - Returns String
uri - can be local disk path or http url
xpath - should be a valid xpath
mcApi.xml().readAsList(uri, xpath) - Returns List<Map<String, String>>
uri - can be local disk path or http url
xpath - should be a valid xpath
mcApi.xml().update(uri, xpath, value)
uri - should be local disk path
xpath - should be a valid xpath
value - String value will be replaced on xpath
Is it also possible to update the values in the xml file? I don't mean adding new nodes or other fancy stuff, only updating for example /student/details/class from Three to Four.
Yes, now it is possible with,
mcApi.xml().update("/tmp/file-xml-demo.xml", "/student/details[1]/class", "Four");
As far as I read the xpath is just a pointer in the tree of an xml, so there is no option to manipulate items. Maybe there is another function available to do this.
You can call readAsList,
var list = mcApi.xml().readAsList("/tmp/file-xml-demo.xml", "//id[text()='4']/..");
// get first result
var item = list.get(0);
// get name, id, class
item.get("name");
item.get("id");
item.get("class");