久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='NG3bE'></tfoot>
  • <legend id='NG3bE'><style id='NG3bE'><dir id='NG3bE'><q id='NG3bE'></q></dir></style></legend>

    1. <i id='NG3bE'><tr id='NG3bE'><dt id='NG3bE'><q id='NG3bE'><span id='NG3bE'><b id='NG3bE'><form id='NG3bE'><ins id='NG3bE'></ins><ul id='NG3bE'></ul><sub id='NG3bE'></sub></form><legend id='NG3bE'></legend><bdo id='NG3bE'><pre id='NG3bE'><center id='NG3bE'></center></pre></bdo></b><th id='NG3bE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NG3bE'><tfoot id='NG3bE'></tfoot><dl id='NG3bE'><fieldset id='NG3bE'></fieldset></dl></div>

      <small id='NG3bE'></small><noframes id='NG3bE'>

        <bdo id='NG3bE'></bdo><ul id='NG3bE'></ul>

        Java XPath:使用默認命名空間 xmlns 進行查詢

        Java XPath: Queries with default namespace xmlns(Java XPath:使用默認命名空間 xmlns 進行查詢)

        <small id='AnNvE'></small><noframes id='AnNvE'>

        <legend id='AnNvE'><style id='AnNvE'><dir id='AnNvE'><q id='AnNvE'></q></dir></style></legend>
          <tbody id='AnNvE'></tbody>
        • <bdo id='AnNvE'></bdo><ul id='AnNvE'></ul>
          <i id='AnNvE'><tr id='AnNvE'><dt id='AnNvE'><q id='AnNvE'><span id='AnNvE'><b id='AnNvE'><form id='AnNvE'><ins id='AnNvE'></ins><ul id='AnNvE'></ul><sub id='AnNvE'></sub></form><legend id='AnNvE'></legend><bdo id='AnNvE'><pre id='AnNvE'><center id='AnNvE'></center></pre></bdo></b><th id='AnNvE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AnNvE'><tfoot id='AnNvE'></tfoot><dl id='AnNvE'><fieldset id='AnNvE'></fieldset></dl></div>

                  <tfoot id='AnNvE'></tfoot>
                  本文介紹了Java XPath:使用默認命名空間 xmlns 進行查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想對此文件進行 XPath 查詢(顯示摘錄):

                  I want to do an XPath query on this file (excerpt shown):

                  <?xml version="1.0" encoding="UTF-8"?>
                  <!-- MetaDataAPI generated on: Friday, May 25, 2007 3:26:31 PM CEST -->
                  <ModelClass xmlns="http://xml.sap.com/2002/10/metamodel/webdynpro" xmlns:IDX="urn:sap.com:WebDynpro.ModelClass:2.0">
                      <ModelClass.Parent>
                          <Core.Reference package="com.test.mypackage" name="ModelName" type="Model"/>
                  

                  這是我正在使用的代碼片段:

                  This is a snippet of the code I'm using:

                  DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
                  DocumentBuilder builder = domFactory.newDocumentBuilder();
                  Document document = builder.parse(new File(testFile));
                  XPathFactory factory = XPathFactory.newInstance();
                  XPath xpath = factory.newXPath();
                  xpath.setNamespaceContext( new NamespaceContext() {
                      public String getNamespaceURI(String prefix) {
                  ...
                  
                  String result = xpath.evaluate(xpathQueryString, document);
                  System.out.println(result);
                  

                  我面臨的問題是,當在 XPath 查詢中引用默認命名空間時,不會調用 getNamespaceURI 方法來解決它.例如,此查詢不會提取任何內容:

                  The problem I'm facing is that when the default namespace is referenced in an XPath query, the getNamespaceURI method is not called to resolve it. This query for example doesn't extract anything:

                  //xmlns:ModelClass.Parent/xmlns:Core.Reference[@type="Model"]/@package

                  現在我嘗試通過將 xmlns 替換為假前綴 d 來欺騙"解析器,然后相應地編寫 getNamespaceURI 方法(所以在遇到 d 時返回 http://xml.sap.com/2002/10/metamodel/webdynpro).在這種情況下,會調用 getNamespaceURI,但 XPath 表達式求值的結果始終是空字符串.

                  Now I've tried "tricking" the parser by replacing xmlns with a fake prefix d and then writing the getNamespaceURI method accordingly (so to return http://xml.sap.com/2002/10/metamodel/webdynpro when d is encountered). In this case, the getNamespaceURI is called but the result of the XPath expression evaluation is always an empty string.

                  如果我從文件和 XPath 查詢表達式中去除命名空間,我可以得到我想要的字符串 (com.test.mypackage).

                  If I strip out namespaces from the file and from the XPath query expression, I can get the string I wanted (com.test.mypackage).

                  有沒有辦法讓默認命名空間正常工作?

                  Is there a way to make things work properly with the default namespace?

                  推薦答案

                  在您的 Namespace 上下文中,將您選擇的前綴(例如 df)綁定到命名空間 URI在文檔中

                  In your Namespace context, bind a prefix of your choice (e.g. df) to the namespace URI in the document

                  xpath.setNamespaceContext( new NamespaceContext() {
                      public String getNamespaceURI(String prefix) {
                        switch (prefix) {
                          case "df": return "http://xml.sap.com/2002/10/metamodel/webdynpro";
                          ...
                         }
                      });
                  

                  然后在路徑表達式中使用該前綴來限定元素名稱,例如/df:ModelClass/df:ModelClass.Parent/df:Core.Reference[@type = 'Model']/@package.

                  and then use that prefix in your path expressions to qualify element names e.g. /df:ModelClass/df:ModelClass.Parent/df:Core.Reference[@type = 'Model']/@package.

                  這篇關于Java XPath:使用默認命名空間 xmlns 進行查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                    <bdo id='2ePTG'></bdo><ul id='2ePTG'></ul>
                  • <i id='2ePTG'><tr id='2ePTG'><dt id='2ePTG'><q id='2ePTG'><span id='2ePTG'><b id='2ePTG'><form id='2ePTG'><ins id='2ePTG'></ins><ul id='2ePTG'></ul><sub id='2ePTG'></sub></form><legend id='2ePTG'></legend><bdo id='2ePTG'><pre id='2ePTG'><center id='2ePTG'></center></pre></bdo></b><th id='2ePTG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2ePTG'><tfoot id='2ePTG'></tfoot><dl id='2ePTG'><fieldset id='2ePTG'></fieldset></dl></div>

                      <legend id='2ePTG'><style id='2ePTG'><dir id='2ePTG'><q id='2ePTG'></q></dir></style></legend>

                        <small id='2ePTG'></small><noframes id='2ePTG'>

                          <tfoot id='2ePTG'></tfoot>
                            <tbody id='2ePTG'></tbody>
                          • 主站蜘蛛池模板: 国产一区中文字幕 | h片在线看| 欧美激情一区二区三区 | 99久久久久久 | 色.com | 91网站视频在线观看 | 欧美激情精品久久久久久 | 免费一级做a爰片久久毛片潮喷 | 美女黄18岁以下禁止观看 | 欧美一级久久 | 精品久久久久久亚洲精品 | 久久综合欧美 | av国产精品毛片一区二区小说 | 一区二区三区久久 | 一本一道久久a久久精品综合蜜臀 | 偷拍自拍网站 | 波多野结衣中文字幕一区二区三区 | 女女百合av大片一区二区三区九县 | 亚洲天堂色| 天天曰天天干 | 久久一区二区三区免费 | 999久久久国产精品 欧美成人h版在线观看 | 黄色大片免费看 | 亚洲精品视频免费看 | 国产一区二区欧美 | 日韩中文在线 | 天堂亚洲 | 欧美成人h版在线观看 | 精品福利一区 | 亚洲网站免费看 | 97人人干 | 91久久国产综合久久 | 亚洲精品久久久一区二区三区 | 99精品国产在热久久 | 中文字幕欧美一区 | 久久九九色 | 亚洲3p| 九九九久久国产免费 | 国产在线一区二区 | 免费精品一区 | 日本欧美在线观看视频 |