posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          java xml basex 數(shù)據(jù)庫(kù)

          Posted on 2008-06-04 16:04 G_G 閱讀(1762) 評(píng)論(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();
          ??}
          }


          結(jié)果:
          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>


          數(shù)據(jù)來(lái)源:
          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>


          主站蜘蛛池模板: 定陶县| 淄博市| 合川市| 南康市| 长武县| 屏山县| 柳州市| 石泉县| 若尔盖县| 莎车县| 甘德县| 淮滨县| 定远县| 革吉县| 清水河县| 德令哈市| 定陶县| 融水| 东乌珠穆沁旗| 滦南县| 庆云县| 张掖市| 清苑县| 石狮市| 万州区| 石泉县| 黄大仙区| 高淳县| 古丈县| 武威市| 两当县| 高台县| 昌平区| 阿合奇县| 依兰县| 永新县| 海城市| 黄陵县| 内江市| 大田县| 刚察县|