如何在android中的特定节点写入XMl?

时间:2012-06-29 07:16:42

标签: android xml xml-parsing

我有一个像这样的XML文件

<?xml version="1.0" encoding="utf-8"?>
<Survey 
Name="Aerosmith's Survey" 
Id="S2"
UserId="Admin"
CreatedBy="Administrator"
cultureName="en-CA" 
numberOfQuestions="5"
completedPercent="0" 
createdTimeStamp="June 26, 2012 16:01" 
lastUpdatedTimeStamp="">
<Questions>
<Question
    id="q1"
    name="Question #1" 
    type="SingleChoice" 
    allowBackButton="false" 
    isRequired="true" 
    numLines="0" 
    questionIndex="1">
        <QuestionText>Who is your favourite Aerosmith's Member ?</QuestionText>
        <Answers>
            <Answer answerIndex="1" >Joey Kramer</Answer>
            <Answer answerIndex="2" >Steven Tyler</Answer>
            <Answer answerIndex="3" >Tom Hamilton</Answer>
            <Answer answerIndex="4" >Joe Perry</Answer>
            <Answer answerIndex="4" >Brad Whitford</Answer>
        </Answers>
        <Response respondedTimeStamp=""></Response>
        <OnChoice></OnChoice>
    </Question>
    <Question 
        id="q2"
        name="Question #2" 
        type="MultipleChoice" 
        allowBackButton="true" 
        isRequired="true" 
        numLines="0" 
        questionIndex="2">
        <QuestionText> Which is your favourite Aerosmith Song ?</QuestionText>
        <Answers>
            <Answer answerIndex="1" >Dream On</Answer>
            <Answer answerIndex="2" >Sweet Emotion</Answer>
            <Answer answerIndex="3" >Walk this way!!</Answer>
            <Answer answerIndex="4" >I Don't Want to Miss a Thing</Answer>
            <Answer answerIndex="5" >Jaded</Answer>
        </Answers>
        <Response respondedTimeStamp=""></Response>
        <OnChoice></OnChoice>
    </Question>
    <Question 
        id="q3"
        name="Question #3" 
        type="Date" 
        allowBackButton="true" 
        isRequired="true" 
        numLines="0" 
        questionIndex="3">
        <QuestionText>What is Your Date of birth?</QuestionText>
        <Answers></Answers>
        <Response respondedTimeStamp=""></Response>
        <OnChoice></OnChoice>
    </Question>
</Questions>
</Survey>

现在在我的应用程序中,我使用SAX解析器来阅读这些内容。 现在每个问题都有一个问题类型,你可以在我的xml中看到。

<Question
    id="q1"
    name="Question #1" 
    type="SingleChoice" 
    allowBackButton="false" 
    isRequired="true" 
    numLines="0" 
    questionIndex="1">

基于此我在列表视图中填充了我的Checkbox。

现在我要做的是假设任何用户在标签中检查项目

<Response respondedTimeStamp=""></Response>

我必须将时间戳和响应值写为该特定问题的文本。

那我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以使用 XStream 库将数据写入xml。