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);
        }
    }

}

你可能感兴趣的:(xfire)