PDA

View Full Version : [Q] Urgent!!! Oracle::Java::XML



conlagia
20-11-2002, 14:10
Các anh chị làm ơn giúp tui với,
tui dùng cái Oracle XML-SQL Utility (XSU) và cái Oracle XML Parser để transform database ra XML, sau đó apply cái XSL vào cái XML và cho ra HTML...
1. Thế nhưng cứ Select ra là nó encode của tui (ví dụ tui insert sourcecode của một trang web vào database, select ra được toàn & < > &quot ... Vậy phải làm thế nào?
2. Hai cái khái niệm XMLDocument (của oracle) và String?
3. Tui đang dùng Oracle9iAS Release 2, JBuilder 7. Còn dưới đây là cái code đó


public void newsGeneration(long articleID, String siteName, String p_xslFile)
throws Exception {

// File separator
String l_fileSep = System.getProperty("file.separator");

// Get the top five elements in descending order from the database
String l_query = "select a.title \"Title\",a.lead \"Lead\",a.site_id,"+
"a.cate_id \"Sub_Cat\",c.parent_cate \"Cat\", a.content \"Content\" "+
"from articles a,categories c where a.id=" + articleID +" and a.cate_id=c.cate_id";

p_xslFile = m_dynNewsEnv.m_dynNewsHome + l_fileSep + p_xslFile;

String p_htmlDir = m_dynNewsEnv.m_dynNewsOut.get(siteName).toString() ;
if (!(new File(p_htmlDir).isDirectory())) {
new File(p_htmlDir).mkdirs();
}
String p_htmlFile = p_htmlDir + l_fileSep + articleID + ".html";

// Execute the Query using Oracle XML SQL utility
OracleXMLQuery l_xmlQuery = new OracleXMLQuery(m_connection,l_query);

// Sets default encoding
l_xmlQuery.setEncoding(null);

// Set Rowset & Row tag
l_xmlQuery.setRowsetTag("News");
l_xmlQuery.setRowTag("News_Item");

// Get the XML Document
XMLDocument l_xmlDocument = (XMLDocument)l_xmlQuery.getXMLDOM();

// Transform the XML into HTML using the style Sheet provided
String l_html = m_xmlHandler.applyXSLtoXML(l_xmlDocument,p_xslFile );

File l_file = new File(p_htmlFile);

// Write the HTML into the file.
FileOutputStream l_fileout = new FileOutputStream(l_file);

// Print the html String
l_fileout.write(l_html.getBytes("UTF8"));

l_fileout.close(); // Close the stream

l_xmlQuery.close(); // Close the XML SQL Utility
}

quangvu
23-11-2002, 10:28
Mình chưa từng dung O. ,nhưng có thể O. hay cái XML của bạn đã mã hoá dữ liệu trước khi trả lại cho bạn thao tác.Bạn thử tìm một thuộc tính nào đó của chúng nó trồi tắt cái "Encode" đi.
Một cách nửa là bạn thử đừng dùng XML đễ truy xuất mà dùng Java connect hay thông qua SOAP thử xem.Biết đâu được đấy :) .
Chúc thành công .