我的活动课程如下:
AssetManager assetmgr= getAssets();
String list[] = assetmgr.list("subdir");
if (list != null) {
DocumentBuilder builder =DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(getAssets().open("subdir/fullSurvey.xml"));
xml对象类如下所示:
NodeList root = doc.getElementsByTagName("root");
NodeList nlQuestions = root.item(0).getChildNodes();
QuestionObject[] allQuestions = new QuestionObject[nlQuestions.getLength()];
for (int i = 0; i < nlQuestions.getLength(); i++) {
Node question = nlQuestions.item(i);
NodeList childNodes = question.getChildNodes();
QuestionObject x = new QuestionObject();
for (int j = 0; j < childNodes.getLength(); j++) {
Node child = childNodes.item(j);
if (child.getNodeName() !="#text") {
Questions t = Questions.valueOf(child.getNodeName());
// etc.
我不知道如何根据属性值
解析xml文件答案 0 :(得分:0)
我不知道许多XML解析器会根据属性值进行遍历。大多数处理节点,节点列表等。您可能必须自己读取所有节点并通过属性值进行哈希。