xFire迭代獲取對象中的值

import java.net.URL;
import org.codehaus.xfire.client.Client;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ServiceClassTest {

    public static void main(String[] args) throws Exception {
        Document xmlTree = (Document) names[0];
        anylizeElement(xmlTree);
    }

    private static void anylizeElement(Document xmlTree) {
        Element element = xmlTree.getDocumentElement();

        //解析dom下的子節點
        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            //拿到節點之後,再去進行解析
            stepThrough(node);
        }
    }

    private static void stepThrough(Node start) {
        //節點下第一個節點開始,遍歷不爲空的節點
        for (Node child = start.getFirstChild(); child != null; child = child.getNextSibling()) {
            if (child instanceof Node)// 去除多餘的空白
            {
                //拿到節點名稱和值
                System.out.print("節點名:" + child.getNodeName());
                System.out.println("\t節點值:" + child.getNodeValue());
            }

            //遞歸遍歷
            if (child != null) stepThrough(child);
        }
    }

}
發佈了96 篇原創文章 · 獲贊 11 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章