私はこのようなXMLファイルを持っています:
<?xml version="1.0"?>
<settings>
<mail id="sender">
<host>content here</host>
<port>25</port>
<account>tmt@example.com</account>
<password>password</password>
</mail>
<mail id="receiver">
<account>tmt@example.com</account>
</mail>
<mail id="support">
<account>tmt@example.com</account>
</mail>
</settings>
attribute
それぞれのを取得し、それぞれelement
のコンテンツを解析して、コンテンツをelement
に保存するにはどうすればよいですか?SharedPreference
これは私がこれまでに行ったことです:
建設業者:
public ReadConfig(Context context, ProgressBar progressBar) throws ParserConfigurationException, SAXException, IOException {
this.context = context;
this.progressBar = progressBar;
folders = new CreateApplicationFolder();
dbf = DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
doc = db.parse(new File(folders.getPathToNode() + "/settings_config.xml"));
doc.getDocumentElement().normalize();
}
そして私のdoInBackground
方法
@Override
protected String doInBackground(String... params) {
Log.i("ROOT NODE: ", doc.getDocumentElement().getNodeName());
NodeList listOfMail = doc.getElementsByTagName("mail");
int totalMail = listOfMail.getLength();
Log.i("LENGTH: ", Integer.toString(totalMail));
for(int i = 0; i < totalMail; i++) {
Node firstMailSetting = listOfMail.item(i);
}
}
私は3つあるLogCat
ことを知っていelements
ます。それは正しいです。