?? parserxml.java~15~
字號:
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;
import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.Element;
import org.jdom.Attribute;
/**
* <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;
//DocumentBuilder builder = factory.newDocumentBuilder();
//document = builder.parse( file );
SAXBuilder builder = new SAXBuilder();
try
{
Document doc = builder.build(file);
return doc;
}catch(JDOMException ex)
{
ex.printStackTrace();
}
return null;
}
public List getDbFrDoc(Document doc)
{
LinkedList rBeacon=new LinkedList();
Element root=doc.getRootElement();
List nl=root.getChildren();
System.out.println("root:"+root.getName()+" chlid length:"+nl.size());
for(int i=0;i<nl.size();i++)
{
Element databaseEle=(Element)nl.get(i);
System.out.println("dbName:"+databaseEle.getName());
if(databaseEle.getName().equals("database"))
{
LinkedList llist=getTablesList(databaseEle);
rBeacon.add(llist);
}
}
return rBeacon;
}
public LinkedList getTablesList(Element dbEle)
{
LinkedList tablesList=new LinkedList();
List nl=dbEle.getChildren();
System.out.println("table count:"+nl.size());
for(int i=0;i<nl.size();i++)
{
Element tableEle=(Element)nl.get(i);
LinkedList tableProList=getTableProList(tableEle);
tablesList.add(tableProList);
}
return tablesList;
}
public LinkedList getTableProList(Element tableEle)
{
LinkedList tableProList=new LinkedList();
List nl=tableEle.getAttributes();
for(int i=0;i<nl.size();i++)
{
Attribute attrNode=(Attribute)nl.get(i);
String colName=attrNode.getValue();
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 + -