【发布时间】:2010-08-18 18:10:14
【问题描述】:
我的 XML 看起来像:
<key>A</key>
如何在 Eclipse 中使用 java 从 XML 中提取字符串“A”? 我的 Java 代码如下所示:
XmlResourceParser xmlSymptoms = getResources().getXml(R.xml.symptoms);
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
// Get the name of the tag (eg scores or score)
String strName = xmlSymptoms.getName();
if (strName.equals("key")) {
keyName = xmlSymptoms.getAttributeName(0);
keyA = xmlSymptoms.getAttributeValue(0);
}
}
eventType = xmlSymptoms.next();
}
但我认为 AttributeName 和 AttributeValue 适用于作为关键描述一部分的项目,即它们将用于获取“项目”和“第一”。
<key item="first">A</key>
我用什么来获取之间的字符串
“<key>”
和
“</key>”?
【问题讨论】: