?? parserxml.java~13~
字號:
package xmltotable;import java.io.File;import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.Document;import javax.xml.parsers.DocumentBuilder;import org.xml.sax.SAXParseException;import org.xml.sax.SAXException;import java.io.IOException;import java.util.LinkedList;import java.util.List;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.xml.sax.Attributes;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class ParserXml { File file; DocumentBuilderFactory factory ; public ParserXml() { factory = DocumentBuilderFactory.newInstance(); } public Document parserFile(File file) { Document document; List list; try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse( file ); return document; } catch (SAXException spe) { spe.printStackTrace(); } catch(IOException ex) { ex.printStackTrace(); } catch(Exception exe) { exe.printStackTrace(); } return null; } public List getDbFrDoc(Document doc) { LinkedList rBeacon=new LinkedList(); Element root=doc.getDocumentElement(); NodeList nl=root.getChildNodes(); System.out.println("root:"+root.getNodeName()+" chlid length:"+nl.getLength()); for(int i=0;i<nl.getLength();i++) { Element databaseEle=(Element)nl.item(i+1); System.out.println("dbName:"+databaseEle.getNodeName()); if(databaseEle.getTagName().equals("database")) { LinkedList llist=getTablesList(databaseEle); rBeacon.add(llist); } } return rBeacon; } public LinkedList getTablesList(Element dbEle) { LinkedList tablesList=new LinkedList(); NodeList nl=dbEle.getChildNodes(); System.out.println("table count:"+nl.getLength()); for(int i=0;i<nl.getLength();i++) { Element tableEle=(Element)nl.item(i+1); LinkedList tableProList=getTableProList(tableEle); tablesList.add(tableProList); } return tablesList; } public LinkedList getTableProList(Element tableEle) { LinkedList tableProList=new LinkedList(); NamedNodeMap nl=tableEle.getAttributes(); for(int i=0;i<nl.getLength();i++) { Node attrNode=nl.item(i); String colName=attrNode.getNodeValue(); System.out.println("nodeValue:"+colName); tableProList.add(colName); } return tableProList; } //public parseFile() public static void main(String[] args) { }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -