📄 domxml.java
字号:
package com.sxjsuper.util;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class DomXml
{
private String path="";
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Map listSqlXml()
{
HashMap<String, String> sqlMap=new HashMap<String, String>();
String name = null,value = null;
File file=new File(path);
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse(file);
NodeList nodeList=doc.getElementsByTagName("sql");
for(int i=0;i<nodeList.getLength();i++)
{
Node child=nodeList.item(i);
NodeList childList=child.getChildNodes();
for(int j=0;j<childList.getLength();j++)
{
Node node=childList.item(j);
if(j%2==0)
{
continue;
}
value=node.getFirstChild().getNodeValue();
if(j<2)
name=node.getFirstChild().getNodeValue();
}
sqlMap.put(name, value);
}
return sqlMap;
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
return null;
}
catch (SAXException e)
{
e.printStackTrace();
return null;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -