1

我有一个这样的 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">

基于此,我在列表视图中填充了我的复选框。

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

<Response respondedTimeStamp=""></Response>

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

那么我该怎么做呢?

4

1 回答 1

0

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

于 2012-06-29T07:25:12.613 回答