ʹÓÃdom4j¶ÁÈ¡xmlÎļþ
Ê×ÏȽ«dom4j-1.6.1.jar,jaxen-1.1.1.jarÁ½¸öjar°üµ¼Èëµ½ÏîÄ¿ÖÐ
reader_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<db-info>
<driver-name>oracle.jdbc.driver.OracleDriver</driver-name>
<url>jdbc:oracle:thin:@192.168.1.100:1521:orcl</url>
<username>dys</username>
<password>dys</password>
</db-info>
</config>
ConfigReader.java
package com.deng.dys.util;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ConfigReader {
private JdbcInfo jdbcInfo ;
// ¾²Ì¬µÄ˽ÓеijÉÔ±±äÁ¿
private static ConfigReader configReader = new ConfigReader();
// ²»ÔÊÐí±ðÈË·ÃÎÊ
private ConfigReader() {
try {
Document document = new SAXReader().read(Thread.currentThread()
.getContextClassLoader().getResourceAsStream(
"reader_config.xml"));
Element driverName = (Element)document.selectObject("/config/db-info/driver-name");
Element url = (Element)document.selectObject("/config/db-info/url");
Element username = (Element)document.selectObject("/config/db-info/username");
Element password = (Element)document.selectObject("/config/db-info/password");
jdbcInfo = new JdbcInfo();
jdbcInfo.setDriverName(driverName.getStringValue());
jdbcInfo.setPassword(password.getStringValue());
jdbcInfo.setUrl(url.getStringValue());
jdbcInfo.setUsername(username.getStringValue());
} catch (Exception e) {
e.printStackTrace();
}
}
// ¹«¹²µÄ¾²Ì¬µÄÈë¿Úµã·½·¨
public static ConfigReader getInstance() {
return configReader;
}
public JdbcInfo getJdbcInfo(){
return jdbcInfo;
}
//main method
public static void main(String args[]){
ConfigReader.getInstance().getJdbcInfo();
}
}
½«xmlµÄÐÅÏ¢·â×°ÔÚÒ»¸öÀàÖÐ
JdbcInfo.java
package com.deng.drp.util;
public class JdbcInfo {
private String driverName;
private String url;
private String usern
Ïà¹ØÎĵµ£º
×î³£¼ûµÄXMLÊý¾ÝÀàÐÍÓУºElement, Attribute£¬Comment, Text.
Element, Ö¸ÐÎÈç<Name>Tom<Name>µÄ½Úµã¡£Ëü¿ÉÒÔ°üÀ¨£ºElement, Text, Comment, ProcessingInstruction, CDATA, and EntityReference.
Attribute, Ö¸ÔÚ<Employee >Ö ......
Standards
"DTD" was the first formalized standard, but is rarely used anymore.
"XDR" was an early attempt by Microsoft to provide a more comprehensive standard than DTD. This standard has pretty much been abandoned now in favor of XSD.
"XSD" is currently the de facto standard for describing XML d ......
±ÊÕßÔÚJava¿ª·¢Öг£³£»áÓöµ½½«Êý¾Ý¿âÊý¾Ýµ¼³öµ½ExcelµÄÒªÇ󣬱ÈÈçÔÚÎÒµÄÒ»¸öÏîÄ¿ÖУ¬¿Í»§ÒªÇóËùÓвéѯ½á¹û¶¼¿ÉÒÔµ¼³öµ½Excel£¬¶ÔÓÚÊý¾ÝÁ¿²»´óµÄ£¨¼¸ÍòÌõ£©£¬Õâ±È½ÏÈÝÒ×ʵÏÖ£¬µ«¶ÔÓÚÊý¾ÝÁ¿±È½Ï´óµÄ£¨¼¸Ê®Íò¼°ÒÔÉÏ£¬¾ßÌåÒª¿´µ¼³öÄÚÈݵÄ×ֶθöÊýºÍ³¤¶Ì£©£¬ÔòÔÚÊý¾Ý¿â²éѯºÍÉú³ÉexcelÎļþÉ϶¼»áÓÐÂé·³¡£
ÒÔÎÒÔÚʵ¼ÊÏîÄ¿ÖеÄÒ»¸ ......
Ò»°ãxmlÖÐÈç¹ûº¬ÓÐ&µÈ×Ö·û£¬¿ÉÒÔͨ¹ýCDATAÀ´¹ýÂË£¬µ«ÊǺ¬ÓÐһЩ²»ÈÏʶµÄÌØÊâ×Ö·ûʱºò¾Í»á²»Æð×÷Óã¬ÏÂÃæÊÇ´Ó±ðÈËÄǶùÄÃÀ´µÄÒ»¸ö¹ýÂË·½
·¨£¬¹ýÂËxmlÖеķǷ¨×Ö·û:
//XML±ê×¼¹æ¶¨µÄÎÞЧ×Ö½ÚΪ£º
/*
0×00 – 0×08
0×0b – 0×0c
0×0e – 0×1f
* ......