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

使用 Child 進(jìn)行 XML 解析而不是值解析

XML parsing with Child not value parsing(使用 Child 進(jìn)行 XML 解析而不是值解析)
本文介紹了使用 Child 進(jìn)行 XML 解析而不是值解析的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

使用 Child 解析 XML 而非值解析

XML parsing with Child not value parsing

   import java.io.File;
   import java.io.FileInputStream;

   import javax.xml.xpath.XPath;
   import javax.xml.xpath.XPathConstants;
   import javax.xml.xpath.XPathFactory;

   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   import org.xml.sax.InputSource;

   import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList;

    public class XPathEvaluator {
    /*
   * ServiceGroup serviceGroup = new ServiceGroup(); List<Service>
    * requiredServices = new ArrayList<Service>(); List<Service>
  * recommandedServices = new ArrayList<Service>(); Service service = new
  * Service();
  */

public void evaluateDocument(File xmlDocument) {

    try {
        XPathFactory factory = XPathFactory.newInstance();
        XPath xPath = factory.newXPath();
        String requiredServicesExpression = "/Envelope/Header";
        InputSource requiredServicesInputSource = new InputSource(
                new FileInputStream(xmlDocument));
        DTMNodeList requiredServicesNodes = (DTMNodeList) xPath.evaluate(
                requiredServicesExpression, requiredServicesInputSource,
                XPathConstants.NODESET);
        System.out.println(requiredServicesNodes.getLength());
        NodeList requiredNodeList = (NodeList) requiredServicesNodes;

        for (int i = 0; i < requiredNodeList.getLength(); i++) {
            Node node = requiredNodeList.item(i);
            System.out.println(node.getChildNodes());

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] argv) {
    XPathEvaluator evaluator = new XPathEvaluator();
    File xmlDocument = new File("d://eva.xml");
    evaluator.evaluateDocument(xmlDocument);

 }

}

我的 xml 在此我正在嘗試解析標(biāo)頭信息

my xml is following in this i am try to parse header information

   <?xml version="1.0" encoding="UTF-8"?>
   <Envelope>
       <Header>
            <User id="MAKRISH"/>
            <Request-Id id="1"/>
            <Type name="Response"/>
            <Application-Source name="vss" version="1.0"/>
            <Application-Destination name="test" />
            <Outgo-Timestamp date="2012-08-24" time="14:50:00"/>
            <DealerCode>08301</DealerCode>
            <Market>00000</Market>
        </Header>
   </Envelope>

我無法獲取 Header 子項,如何獲取它們在 getchildNodes 方法上給我 null.我已經(jīng)檢查了很多解決方案,但得到了任何東西.

i am not able to get Header child how can i get them it is giving me null on getchildNodes method. i have check for many solution but get any thing.

推薦答案

this related question 有一個使用 xpath 解析 xml 的好例子.

The accepted answer to this related question has a good example of parsing xml using xpath.

我已經(jīng)調(diào)試了你的代碼,getChildNodes 調(diào)用實際上并沒有返回 null,但是它有一個令人困惑的 toString().

I've debugged into your code, and the getChildNodes call is in fact not returning null, but it has got a confusing toString().

這篇關(guān)于使用 Child 進(jìn)行 XML 解析而不是值解析的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Upload progress listener not fired (Google drive API)(上傳進(jìn)度偵聽器未觸發(fā)(Google 驅(qū)動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅(qū)動api服務(wù)賬戶查看上傳文件到谷歌驅(qū)動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務(wù)帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 午夜小视频在线播放 | 精品久久久久久久久久久久 | 成人午夜视频在线观看 | 亚洲精品国产一区 | 一级片在线免费看 | 精品1区2区 | 午夜私人影院在线观看 | 亚洲成人免费视频在线观看 | 别c我啊嗯国产av一毛片 | 国产亚洲一区二区在线观看 | 日本三级日产三级国产三级 | 欧美一区二区在线观看 | 2018国产精品 | 亚洲一区播放 | 久久国产福利 | 国产区视频在线观看 | 91在线观看 | 手机看片1 | 亚洲精品久久嫩草网站秘色 | 黄色一级电影免费观看 | 2020天天操| 人人色视频 | 国产一级片 | 999免费观看视频 | 九色视频网站 | 亚洲 自拍 另类 欧美 丝袜 | 免费a网| 国产高清区 | 欧美极品少妇xxxxⅹ免费视频 | 午夜a区 | 国产精品一区视频 | 毛片一区二区 | 男人影音 | 天天综合干 | 亚洲传媒在线 | 91中文字幕在线观看 | 色欧美片视频在线观看 | 黄色网址在线免费观看 | 性欧美xxxx| 国产一区二区三区免费 | 成人免费大片黄在线播放 |