您現在的位置是:首頁 >要聞 > 2023-12-14 22:36:20 來源:
javahdvideos日本
大家好,我是小夏,我來為大家解答以上問題。javahdvideos日本很多人還不知道,現在讓我們一起來看看吧!
1、使用大致如下:
2、//首先獲取xml的數據源連接
3、XQDataSource ds = new SaxonXQDataSource();
4、XQConnection conn = ds.getConnection();
5、//通過XQExpression執行xquery
6、XQExpression expression = conn.createExpression();
7、XQResultSequence res=expression.executeQuery("doc(persons.xml)//person....");
8、//處理結果集
9、while(res.next()){
10、res.getObject();
11、}
12、另外:
13、xquery的doc()函數需要傳遞xml的文檔路徑,然而在開發時,我們的xml數據源可能還沒有生成文件,對此,XQExpression提供了API,可以直接綁定xml數據而不用加載xml文檔
14、expression.bindNode(XQConstants.CONTEXT_ITEM, org.w3c.dom.Document doc, null);
15、doc對象可通過DocumentBuilder類生成
16、DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
17、DocumentBuilder db = dbf.newDocumentBuilder();
18、Document doc=db.parse(new ByteArrayInputStream("<person>zhangsan</person>".getBytes()));
本文到此講解完畢了,希望對大家有幫助。