大家來討論 JAVA + JSP + XML ~~~ |
答題得分者是:skini
|
csie
一般會員 發表:8 回覆:5 積分:2 註冊:2002-09-14 發送簡訊給我 |
不知道有沒有人知道如何使用
JSP 取得 *.xml 的 tag...
我目前 Sun 的 java_xml_pack-summer02_01 其中的 Jaxp 作為 Paser
使用 SAX and DOM
可是我不會使用....
看的 doc 並沒有說有關於 import 什麼...
是不是還要自己寫 class 以下是 Sample..
----------------------------------------------------------------------
This code is abstracted from the SAX example: SAXParserFactory spf = SAXParserFactory.newInstance(); // Set namespaceAware to true to get a parser that corresponds to
// the default SAX2 namespace feature setting. This is necessary
// because the default value from JAXP 1.0 was defined to be false.
spf.setNamespaceAware(true);
spf.setValidating(true); SAXParser saxParser = spf.newSAXParser(); // Set the schema language if necessary
try {
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
} catch (SAXNotRecognizedException x) {
// This can happen if the parser does not support JAXP 1.2
...
}
...
saxParser.setProperty(JAXP_SCHEMA_SOURCE, new File(schemaSource));
And here is the code abstracted from the DOM example: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Set namespaceAware to true to get a DOM Level 2 tree with nodes
// containing namesapce information. This is necessary because the
// default value from JAXP 1.0 was defined to be false.
dbf.setNamespaceAware(true); dbf.setValidating(true);
try {
dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
} catch (IllegalArgumentException x) {
// This can happen if the parser does not support JAXP 1.2
...
}
// Specify other factory configuration settings
dbf.setAttribute(JAXP_SCHEMA_SOURCE, new File(schemaSource));
...
DocumentBuilder db = dbf.newDocumentBuilder(); 發表人 - csie 於 2002/12/09 23:05:55
|
skini
一般會員 發表:2 回覆:30 積分:16 註冊:2002-04-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |