糯米文學吧

位置:首頁 > IT認證 > J2EE

關於XML方面的面試題及答案

J2EE2.69W

XML指的是可擴展標記語言,標準通用標記語言的子集,是一種用於標記電子文件使其具有結構性的標記語言。下面YJBYS小編為大家整理了關於XML方面的面試題及答案,希望對你有所幫助。

關於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內容顯示源碼,:

標籤:面試題 XML