34 lines
1.2 KiB
Java
34 lines
1.2 KiB
Java
package eu.dnetlib.validatorapi.utils;
|
|
|
|
public class XmlProcessor { /* implements Processor {
|
|
private List<Element> elements;
|
|
|
|
@Override
|
|
public void process(Exchange exchange) throws Exception {
|
|
String xml = exchange.getIn().getBody(String.class);
|
|
|
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
|
Document doc = dBuilder.parse(new InputSource(new StringReader(xml)));
|
|
|
|
XPathFactory xfactory = XPathFactory.newInstance();
|
|
XPath xpath = xfactory.newXPath();
|
|
XPathExpression recordsExpression = xpath.compile("//record");
|
|
NodeList recordNodes = (NodeList) recordsExpression.evaluate(doc, XPathConstants.NODESET);
|
|
|
|
elements = nodeListToList(recordNodes); // assign the Elements to the variable
|
|
}
|
|
|
|
private List<Element> nodeListToList(NodeList nodeList) {
|
|
List<Element> list = new ArrayList<>();
|
|
for (int i = 0; i < nodeList.getLength(); i++) {
|
|
list.add((Element) nodeList.item(i));
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public List<Element> getElements() {
|
|
return elements;
|
|
}*/
|
|
}
|