Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » WebService/XML/JSON/SOAP/SOA » XML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 DOM 解析XML
xbaole





发贴: 5
积分: 0
于 2008-12-26 21:18 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class dse {

  public static void gos(Node node) {
    for (Node nod = node.getFirstChild(); nod != null; nod = nod.getNextSibling())
    {
      if(nod.getNodeType()==1)
      {
        System.out.println(node.getNodeName());
        if (nod.hasAttributes())
        {
          NamedNodeMap nods = nod.getAttributes();
          for (int j = 0; j < nods.getLength(); j++)
          {
            System.out.print(nods.item(j).getNodeName()+"\t");
          }
        }
      }
      if(nod.hasChildNodes())
      {
        gos(nod);
      }
    }
  }

  public static void main(String[] args) {

    File file = new File("src\\ffs\\a.xml");

    Document doc = null;
    Document newdoc = null;

    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setValidating(true);
      DocumentBuilder dbu = dbf.newDocumentBuilder();
      doc = dbu.parse(file);
      newdoc = dbu.newDocument();
    } catch (Exception e) {
      e.printStackTrace();
    }
    Element root = doc.getDocumentElement();

  }
}




话题树型展开
人气 标题 作者 字数 发贴时间
9787 DOM 解析XML xbaole 1258 2008-12-26 21:18

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2018 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923