posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          java xml basex 數據庫

          Posted on 2008-06-04 16:04 G_G 閱讀(1764) 評論(0)  編輯  收藏 所屬分類: xml RelatedjavaGeneral
          官方:
          BaseX Logo
          eg:xquery使用
          import?org.basex.core.Commands;
          import?org.basex.core.proc.Proc;
          import?org.basex.data.Result;
          import?org.basex.io.ConsoleOutput;
          import?org.basex.query.QueryException;
          import?org.basex.query.QueryProcessor;
          import?org.basex.query.xquery.XQueryProcessor;

          /**
          ?*?This?class?serves?an?example?for?executing?XQuery?requests.
          ?
          */
          public?final?class?XQueryExample?{
          ??
          /**?Sample?query.?*/
          ??
          private?static?final?String?XMLFILE?=?XPathExample.class.getClassLoader().getSystemResource(
          ??????????????
          "xx.xml"
          ?????????).getPath();
          ??
          ??
          ??
          private?static?final?String?QUERY?=?"?for?$x?in?doc('"+XMLFILE+"')//property?"?+
          ??????????????????????????????????????????????
          "?return?<child>{data($x/@name)}</child>";

          ??
          /**?Private?constructor.?*/
          ??
          private?XQueryExample()?{?}
          ??
          /**
          ???*?Main?method?of?the?example?class.
          ???*?
          @param?args?(ignored)?command-line?arguments
          ???*?
          @throws?Exception?exception
          ???
          */
          ??
          public?static?void?main(final?String[]?args)?throws?Exception?{

          ????
          //?FIRST?EXAMPLE:
          ????System.out.println("First?example:");

          ????
          //?create?standard?output?stream
          ????final?ConsoleOutput?out?=?new?ConsoleOutput(System.out);

          ????
          //?Create?a?BaseX?process
          ????final?Proc?proc?=?Proc.get(Commands.XQUERY,?QUERY);
          ????
          //?launch?process
          ????if(proc.execute())?{
          ??????
          //?successful?execution:?print?result
          ??????proc.output(out);
          ????}?
          else?{
          ??????
          //?execution?failed:?print?result
          ??????proc.info(out);
          ????}
          ????out.flush();
          ????System.out.println();
          ????
          ????
          //?SECOND?EXAMPLE?(ALTERNATIVE):
          ????System.out.println("Second?example:");

          ????
          //?Execute?XQuery?request
          ????try?{
          ??????
          //?create?query?instance
          ??????final?QueryProcessor?xquery?=?new?XQueryProcessor(QUERY);
          ??????
          //?execute?query;?no?initial?context?set?is?specified?(null)
          ??????final?Result?result?=?xquery.query(null);
          ??????
          //?print?output
          ??????result.serialize(out,?false);
          ??????out.println();
          ????}?
          catch(final?QueryException?e)?{
          ??????
          //?dump?stack?trace
          ??????e.printStackTrace();
          ????}

          ????
          //?close?output?stream
          ????out.close();
          ??}
          }


          結果:
          First?example:
          <child>connection.datasource</child>
          <child>dialect</child>
          <child>show_sql</child>
          <child>hibernate.cache.provider_class</child>
          <child>cache.use_query_cache</child>

          Second?example:
          <child>connection.datasource</child>
          <child>dialect</child>
          <child>show_sql</child>
          <child>hibernate.cache.provider_class</child>
          <child>cache.use_query_cache</child>


          數據來源:
          xx.xml
          <?xml?version='1.0'?encoding='utf-8'?>

          <hibernate-configuration>

          ????
          <session-factory>

          ????????
          <property?name="connection.datasource">java:comp/env/jdbc/USERPORTAL1</property>
          ????????
          <property?name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
          ?????????
          <property?name="show_sql">true</property>
          ?????????
          <property?name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
          ?????????
          <property?name="cache.use_query_cache">true</property>
          ????
          <!--?JDBC?connection?pool?(use?the?built-in)?-->

          ????
          </session-factory>

          </hibernate-configuration>


          主站蜘蛛池模板: 天祝| 岱山县| 卢龙县| 海城市| 忻城县| 浠水县| 长泰县| 志丹县| 正阳县| 时尚| 黄石市| 阿勒泰市| 酒泉市| 台中县| 延津县| 湟中县| 长宁区| 那坡县| 闽清县| 定陶县| 荔波县| 宁晋县| 漠河县| 宁乡县| 天等县| 浦城县| 瑞安市| 聊城市| 黄石市| 绥滨县| 拜城县| 古浪县| 广南县| 米脂县| 石阡县| 金乡县| 遂昌县| 苍梧县| 密山市| 封丘县| 汝城县|