關於XML方面的面試題及答案
- J2EE
- 關注:2.55W次
XML指的是可擴充套件標記語言,標準通用標記語言的子集,是一種用於標記電子檔案使其具有結構性的標記語言。下面YJBYS小編為大家整理了關於XML方面的面試題及答案,希望對你有所幫助。
1、xml有哪些解析技術?區別是什麼?
答:有DOM,SAX,STAX等
DOM:處理大型檔案時其效能下降的非常厲害。這個問題是由DOM的樹結構所造成的,這種結構佔用的`記憶體較多,而且DOM必須在解析檔案之前把整個文件裝入記憶體,適合對XML的隨機訪問SAX:不現於DOM,SAX是事件驅動型的XML解析方式。它順序讀取XML檔案,不需要一次全部裝載整個檔案。當遇到像檔案開頭,文件結束,或者標籤開頭與標籤結束時,它會觸發一個事件,使用者通過在其回撥事件中寫入處理程式碼來處理XML檔案,適合對XML的順序訪問
STAX:Streaming API for XML (StAX)
2、你在專案中用到了xml技術的哪些方面?如何實現的?
答:用到了資料存貯,資訊配置兩方面。在做資料交換平臺時,將不能資料來源的資料組裝成XML檔案,然後將XML檔案壓縮打包加密後通過網路傳送給接收者,接收解密與解壓縮後再同XML檔案中還原相關資訊進行處理。在做軟體配置時,利用XML可以很方便的進行,軟體的各種配置引數都存貯在XML檔案中。
3、用jdom解析xml檔案時如何解決中文問題?如何解析?
答:看如下程式碼,用編碼方式加以解決
package test;
import .*;
public class DOMTest
{
private String inFile = "c:";
private String outFile = "c:";
public static void main(String args[])
{
new DOMTest();
}
public DOMTest()
{
try
{
mentBuilder builder =
nstance()ocumentBuilder();
ment doc = ocument();
ent root = teElement("老師");
ent wang = teElement("王");
ent liu = teElement("劉");
ndChild(teTextNode("我是王老師"));
ndChild(wang);
ndChild(root);
sformer transformer =
nstance()ransformer();
utputProperty(DING, "gb2312");
utputProperty(NT, "yes");
sform(new ource(doc),
new
amResult(outFile));
}
catch (Exception e)
{
tln (essage());
}
}
}
4、程式設計用JAVA解析XML的方式.
答:用SAX方式解析XML,XML檔案如下:
王小明
資訊學院
6258113
男,1955年生,博士,95年調入海南大學
事件回撥類
import .*;
import table;
import .*;
public class SAXHandler extends HandlerBase
{
private Hashtable table = new Hashtable();
private String currentElement = null;
private String currentValue = null;
public void setTable(Hashtable table)
{
e = table;
}
public Hashtable getTable()
{
return table;
}
public void startElement(String tag, AttributeList attrs)
throws SAXException
{
currentElement = tag;
}
public void characters(char[] ch, int start, int length)
throws SAXException
{
currentValue = new String(ch, start, length);
}
public void endElement(String name) throws SAXException
{
if (ls(name))
(currentElement, currentValue);
}
}
JSP內容顯示原始碼,:
- 文章版權屬於文章作者所有,轉載請註明 https://xuezhezhai.com/zh-tw/itrz/j2ee/wv2e6l.html