C# 如何迭代包含节点列表的Jdom元素?
我对使用C# 如何迭代包含节点列表的Jdom元素?,c#,java,xml,xpath,xml-parsing,C#,Java,Xml,Xpath,Xml Parsing,我对使用org.jdom.*在Java中解析XML非常陌生,我不懂C 在这段时间里,我不得不将一些方法从C#翻译成Java,我有以下问题 在C#中,我有这样的想法: System.Xml.XmlNodeList nodeList; nodeList = _document.SelectNodes("//root/settings/process-filters/process"); if (nodeList == null || nodeList.Count == 0) { return
org.jdom.*
在Java中解析XML非常陌生,我不懂C
在这段时间里,我不得不将一些方法从C#翻译成Java,我有以下问题
在C#中,我有这样的想法:
System.Xml.XmlNodeList nodeList;
nodeList = _document.SelectNodes("//root/settings/process-filters/process");
if (nodeList == null || nodeList.Count == 0) {
return risultato;
}
Objects.MyItem o;
foreach (System.Xml.XmlNode n in nodeList){
o = new Objects.MyItem(n.ChildNodes[1].InnerText, n.ChildNodes[0].InnerText);
risultato.Add(o);
}
我用Java将其翻译成这样:
public List<ProcessiDaEscludere> getProcessiDaEscludere() {
Vector<ProcessiDaEscludere> risultato = new Vector<ProcessiDaEscludere>();
Element nodeList;
XPath xPath;
try {
// Query XPath che accede alla root del tag <process-filters>:
xPath = XPath.newInstance("//root/settings/process-filters/process");
nodeList = (Element) xPath.selectSingleNode(CONFIG_DOCUMENT);
if (nodeList == null || nodeList.getChildren().size() == 0)
return risultato;
ProcessiDaEscludere processoDaEscludere = new ProcessiDaEscludere();
}catch (JDOMException e){
}
return risultato;
}
有人能帮我吗
foreach (System.Xml.XmlNode n in nodeList){
o = new Objects.MyItem(n.ChildNodes[1].InnerText, n.ChildNodes[0].InnerText);
risultato.Add(o);
}