@Override
public void parse(Consumer<MnoInfo> consumer) throws Exception {
File fXmlFile = config.toFile();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
XPathExpression xpathMno = XPathFactory.newInstance().newXPath().compile("//*[local-name()='mno']");
XPathExpression xpathMasksMno = XPathFactory.newInstance().newXPath().compile("//*[local-name()='mask']");
NodeList mnoNodes = (NodeList) xpathMno.evaluate(doc, XPathConstants.NODESET);
for (int i=0; i<mnoNodes.getLength(); i++) {
Node node = mnoNodes.item(i);
NamedNodeMap attributes = node.getAttributes();
String country = getValue(attributes.getNamedItem("country"));
String title = getValue(attributes.getNamedItem("title"));
String area = getValue(attributes.getNamedItem("area"));
Set<Mask> masks = new HashSet<>();
NodeList maskNodes = (NodeList) xpathMasksMno.evaluate(doc, XPathConstants.NODESET);
for (int j=0; j<maskNodes.getLength(); j++) {
masks.add(Mask.parse(getValue(maskNodes.item(j))));
}
consumer.accept(new MnoInfo(title, area, country, masks));
}
}
CustomMasksParser.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:mnp
作者:
评论列表
文章目录