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

如何用java從xml文件中讀取屬性?

How to read properties from xml file with java?(如何用java從xml文件中讀取屬性?)
本文介紹了如何用java從xml文件中讀取屬性?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有以下 xml 文件:

I have the following xml file:

<resources>
    <resource id="res001">
        <property name="propA" value="A" />
        <property name="propB" value="B" />
    </resource>
    <resource id="res002">
        <property name="propC" value="C" />
        <property name="propD" value="D" />
    </resource>
    <resource id="res003">
        <property name="propE" value="E" />
        <property name="propF" value="F" />
    </resource>
</resources>

我怎樣才能用 Java/Xml 做這樣的事情:

How can I do something like this with Java/Xml:

Xml xml = new Xml("my.xml");
Resource res001 = xml.getResouceById("res003");
System.out.println("propF: " + res.getProperty("propF"));

所以它打印出來:

F

我已經用 XPathExpressionEngine 嘗試了 apache commons-configurations XMLConfiguration,但我就是不能讓它工作.我用谷歌搜索并找到了一些例子,但都不起作用:(我正在尋找一種不需要遍歷所有元素的解決方案.

I have tried apache commons-configurations XMLConfiguration with XPathExpressionEngine, but I just can't make it work. I have googled and found some examples, but neither would work :( I'm looking for a solution where I don't need to loop through all the elements.

問候,亞歷克斯

推薦答案

這很簡單,假設您愿意將屬性文件重寫為標準 Java 格式.假設您在名為 props.xml 的文件中有以下內容:

This is trivial, assuming you're willing to re-write your properties file into the standard Java format. Assume you have the following in a file called props.xml:

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <comment>This is a comment</comment>
    <entry key="propA">A</entry>
    <entry key="propB">B</entry>
    <entry key="propC">C</entry>
    <entry key="propD">D</entry>
    <entry key="propE">E</entry>
    <entry key="propF">F</entry>
</properties>

然后像這樣從文件中讀取屬性:

Then read properties from the file like this:

java.util.Properties prop = new Properties();
prop.loadFromXML(new FileInputStream("props.xml"));
System.out.println(prop.getProperty("propF"));

這篇關于如何用java從xml文件中讀取屬性?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(Google 驅動器 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(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 91在线看片| 国产色婷婷精品综合在线播放 | 日韩欧美一二三区 | 成人在线观看免费 | 午夜精品久久久久久久久久久久久 | 91污在线 | 欧美一区2区三区3区公司 | 懂色一区二区三区免费观看 | 日韩av一区二区在线观看 | 中文字幕乱码亚洲精品一区 | 狠狠色综合欧美激情 | 亚洲国产一区二区三区在线观看 | 紧缚调教一区二区三区视频 | 特级a欧美做爰片毛片 | 久久精品二区亚洲w码 | 国产日韩一区二区三区 | 成人在线视 | 日韩视频在线免费观看 | 在线资源视频 | 国产精品成人一区二区 | 黄色成人av | 国产在线视频一区二区 | 日本一区二区高清不卡 | 久久久精品一区二区三区 | 亚洲欧洲成人av每日更新 | 久久丁香 | 福利社午夜影院 | 91av视频在线播放 | 成人国产精品 | 精品免费国产一区二区三区四区介绍 | 久久久视频在线 | 欧美三区 | 成人水多啪啪片 | 五月网婷婷 | 欧美精品一区在线发布 | 欧美一区二区免费 | 欧美在线观看一区二区 | 日一区二区 | 亚洲精品国产精品国自产在线 | 美女人人操 | 国内精品久久久久久久 |