У меня есть этот документ XML, и я хочу его проанализировать, и я сделал это для его анализа, но у меня есть проблема в методе public public getFunction
, в котором я хочу поместить свои элементы в массив строк.Может ли кто-нибудь сказать, в чем проблема
public void parseXmlFile() {
Document ret = null;
DocumentBuilderFactory domFactory;
DocumentBuilder builder;
ArrayList myFunc = new ArrayList();
try {
domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(false);
domFactory.setNamespaceAware(false);
builder = domFactory.newDocumentBuilder();
ret = builder.parse("test.xml");
}
catch (Exception ex) {
System.err.println("unable to load XML: " + ex);
}
Element docEle = ret.getDocumentElement();
NodeList nl = docEle.getElementsByTagName("Function");
if(nl != null && nl.getLength() > 0) {
for(int i = 0 ; i < nl.getLength();i++) {
Element el = (Element)nl.item(i);
Function e = getFunction(el);
myFunc.add(e);
}
}
}
public Function getFunction (Element empEl) {
String used[] = getTextValue(empEl,"UsedFunctions");
String type = empEl.getAttribute("type");
Function e = new Function(used[] ,type);
return e;
}
public String getTextValue(Element ele, String tagName) {
String textVal = null;
NodeList nl = ele.getElementsByTagName(tagName);
if(nl != null && nl.getLength() > 0) {
Element el = (Element)nl.item(0);
textVal = el.getFirstChild().getNodeValue();
}
return textVal;
}