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

  • <tfoot id='yfSJq'></tfoot>
      <bdo id='yfSJq'></bdo><ul id='yfSJq'></ul>

    1. <legend id='yfSJq'><style id='yfSJq'><dir id='yfSJq'><q id='yfSJq'></q></dir></style></legend>

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

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

        Java中帶有命名空間的XPath

        XPath with namespace in Java(Java中帶有命名空間的XPath)

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

        • <small id='9Miyu'></small><noframes id='9Miyu'>

            <tbody id='9Miyu'></tbody>

                  <tfoot id='9Miyu'></tfoot>

                1. <legend id='9Miyu'><style id='9Miyu'><dir id='9Miyu'><q id='9Miyu'></q></dir></style></legend>

                  本文介紹了Java中帶有命名空間的XPath的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想獲取標簽之間的所有內容,但由于 urn: 命名空間,我不知道該怎么做.

                  I would like to get all the content in between the tags but I do not know how to do this because of the urn: namespace.

                  <urn:ResponseStatus version="1.0" xmlns:urn="urn:camera-org">
                  
                  <urn:requestURL>/CAMERA/Streaming/status</urn:requestURL>
                  <urn:statusCode>4</urn:statusCode>
                  <urn:statusString>Invalid Operation</urn:statusString>
                  <urn:id>0</urn:id>
                  
                  </urn:ResponseStatus>
                  

                  有什么想法嗎?

                  推薦答案

                  1. 簡答:使用 XPath local-name().像這樣: xPathFactory.newXPath().compile("http://*[local-name()='requestURL']/text()"); 將返回 /CAMERA/Streaming/狀態
                  2. 或者您可以實現一個 NamespaceContext 來映射命名空間名稱和 URI,并在查詢之前將其設置在 XPath 對象上.
                  3. 看看這篇博客文章,更新:文章已下架,您可以在webarchive
                  1. Short answer: use XPath local-name(). Like this: xPathFactory.newXPath().compile("http://*[local-name()='requestURL']/text()"); will return /CAMERA/Streaming/status
                  2. Or you can implement a NamespaceContext that maps namespaces names and URIs and set it on the XPath object before querying.
                  3. Take a look at this blog article, Update: the article is down, you can see it on webarchive

                  解決方案 1 示例:

                  XPath xpath = XPathFactory.newInstance().newXPath();
                  String responseStatus = xpath.evaluate("http://*[local-name()='ResponseStatus']/text()", document);
                  System.out.println("-> " + responseStatus);
                  

                  解決方案 2 示例:

                  // load the Document
                  Document document = ...;
                  NamespaceContext ctx = new NamespaceContext() {
                      public String getNamespaceURI(String prefix) {
                          return prefix.equals("urn") ? "urn:camera-org" : null; 
                      }
                      public Iterator getPrefixes(String val) {
                          return null;
                      }
                      public String getPrefix(String uri) {
                          return null;
                      }
                  };
                  XPath xpath = XPathFactory.newInstance().newXPath();
                  xpath.setNamespaceContext(ctx);
                  String responseStatus = xpath.evaluate("http://urn:ResponseStatus/text()", document);
                  System.out.println("-> " + responseStatus);
                  

                  編輯

                  這是一個完整的例子,它正確地檢索了元素:

                  This is a complete example, it correctly retrieve the element:

                  String xml = "<urn:ResponseStatus version="1.0" xmlns:urn="urn:camera-org">
                  " + //
                          "
                  " + //
                          "<urn:requestURL>/CAMERA/Streaming/status</urn:requestURL>
                  " + //
                          "<urn:statusCode>4</urn:statusCode>
                  " + //
                          "<urn:statusString>Invalid Operation</urn:statusString>
                  " + //
                          "<urn:id>0</urn:id>
                  " + //
                          "
                  " + //
                          "</urn:ResponseStatus>";
                  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                  factory.setNamespaceAware(true);
                  DocumentBuilder builder = factory.newDocumentBuilder();
                  Document doc = builder.parse(new java.io.ByteArrayInputStream(xml.getBytes()));
                  XPath xpath = XPathFactory.newInstance().newXPath();
                  xpath.setNamespaceContext(new NamespaceContext() {
                      public String getNamespaceURI(String prefix) {
                          return prefix.equals("urn") ? "urn:camera-org" : null;
                      }
                  
                      public Iterator<?> getPrefixes(String val) {
                          return null;
                      }
                  
                      public String getPrefix(String uri) {
                          return null;
                      }
                  });
                  XPathExpression expr = xpath.compile("http://urn:ResponseStatus");
                  Object result = expr.evaluate(doc, XPathConstants.NODESET);
                  NodeList nodes = (NodeList) result;
                  for (int i = 0; i < nodes.getLength(); i++) {
                      Node currentItem = nodes.item(i);
                      System.out.println("found node -> " + currentItem.getLocalName() + " (namespace: " + currentItem.getNamespaceURI() + ")");
                  }
                  

                  這篇關于Java中帶有命名空間的XPath的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                    <tfoot id='Wrj6i'></tfoot>
                    <i id='Wrj6i'><tr id='Wrj6i'><dt id='Wrj6i'><q id='Wrj6i'><span id='Wrj6i'><b id='Wrj6i'><form id='Wrj6i'><ins id='Wrj6i'></ins><ul id='Wrj6i'></ul><sub id='Wrj6i'></sub></form><legend id='Wrj6i'></legend><bdo id='Wrj6i'><pre id='Wrj6i'><center id='Wrj6i'></center></pre></bdo></b><th id='Wrj6i'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Wrj6i'><tfoot id='Wrj6i'></tfoot><dl id='Wrj6i'><fieldset id='Wrj6i'></fieldset></dl></div>
                    <legend id='Wrj6i'><style id='Wrj6i'><dir id='Wrj6i'><q id='Wrj6i'></q></dir></style></legend>

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

                          <tbody id='Wrj6i'></tbody>

                          <bdo id='Wrj6i'></bdo><ul id='Wrj6i'></ul>
                            主站蜘蛛池模板: 国产久| 欧美中文视频 | 欧美黑人一区二区三区 | 久久国产精品色av免费观看 | 午夜国产 | 中文一区 | 亚洲精品一| 日韩成人高清在线 | 久久久99国产精品免费 | 欧美日韩视频在线 | 日本精品久久久久 | 天天看天天干 | 亚洲九九色 | 成人动慢 | 精品免费国产 | 免费精品国产 | 亚洲精品在线看 | 手机看片169| 亚洲精品久久视频 | 福利网站导航 | 国产精品18hdxxxⅹ在线 | 中文字幕av一区二区三区 | 草草视频在线免费观看 | 日韩在线播放第一页 | 国产区一区二区三区 | 精品视频一区二区三区在线观看 | 久久午夜国产精品www忘忧草 | 国产一区不卡 | 国产一级片久久久 | 午夜影视| 久久爱黑人激情av摘花 | 色综合九九| 精品av天堂毛片久久久借种 | 亚洲男人的天堂网站 | 天天射天天干 | 伊人网99 | 亚洲色图插插插 | 日本精品视频在线 | 中文字幕视频在线看5 | 精品美女久久久久久免费 | 99亚洲精品 |