?? xmlextractor.java
字號(hào):
package Chapter12;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
public class XMLExtractor {
public static String getXMLContent( String filename )
{
SAXBuilder sb = new SAXBuilder();
try
{
Document doc = sb.build(filename); // 生成文檔對(duì)象
Element root = doc.getRootElement(); // 獲取根節(jié)點(diǎn)
String str1 = root.getAttributeValue("comment"); // 獲取根節(jié)點(diǎn)的comment屬性
System.out.println("根節(jié)點(diǎn)說(shuō)明 : " + str1);
String str2 = root.getChild("Listener").getAttributeValue("className"); // 獲取Listner節(jié)點(diǎn)的className屬性
System.out.println("Listener 節(jié)點(diǎn) className 屬性 : " + str2);
String str3 = root.getChild("Service").getAttributeValue("name"); // 獲取Service節(jié)點(diǎn)的name屬性
System.out.println("Service 節(jié)點(diǎn) Name 屬性 : " + str3);
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); // 生成XML的輸出對(duì)象
String outStr = xmlOut.outputString(root); // 輸出根節(jié)點(diǎn)內(nèi)容字符串
System.out.println("");
System.out.println(outStr); // 輸出根節(jié)點(diǎn)內(nèi)容
return outStr;
}catch(Exception e)
{
e.printStackTrace();
return "";
}
}
public static void main(String[] args){
getXMLContent("D:\\workshop\\docs\\server.xml");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -