【问题标题】:Parsing XML for nested tags为嵌套标签解析 XML
【发布时间】:2011-09-24 22:27:55
【问题描述】:

我有一个 XML,我正在将数据转换为如下格式:

<Question>
    <QuestionID>1</QuestionID>
    <QuestionType>Logic</QuestionType>
    <QuestionImage>http://mobilecms.hiteshi.com/IQ/xml/Logic/1/Question/q.jpg</QuestionImage>
    <QuestionText>1 Which is the Next image?</QuestionText>
    <AnswerImages Count="4">
        <Image>http://mobilecms.hiteshi.com/IQ/xml/Logic/1/Answer/a.jpg</Image>
        <Image>http://mobilecms.hiteshi.com/IQ/xml/Logic/1/Answer/b.jpg</Image>
        <Image>http://mobilecms.hiteshi.com/IQ/xml/Logic/1/Answer/c.jpg</Image>
        <Image>http://mobilecms.hiteshi.com/IQ/xml/Logic/1/Answer/d.jpg</Image>
    </AnswerImages>
    <Answer>d</Answer>
    <Score>1</Score>
    <DifficultyLevel>1</DifficultyLevel>
</Question>

我必须读取该 XML 并将所有标签数据存储到两个不同的 sqlite 表中。我可以轻松读取诸如 QuestionID、QuestionType 等主要标签,并将其存储到 tableOne 中。

现在我想读取其中包含计数的 AnswerImages 标记,并根据该计数变量包含名为 &lt;Image&gt; 的子标记。这里我想将所有&lt;Image&gt;标签数据存入tableTwo。

如何将数据同时存储到 tableOne 和 tableTwo 中?

【问题讨论】:

  • 请更正链接。如果您不知道该怎么做,请在发布之前先检查一下。而且就个人而言,这里最好粘贴xml而不是链接。
  • 您使用什么语言,什么平台?我们是否可以通过您的用户名假设这是一个 iphone 应用程序?知道这些问题的答案将有助于人们推荐可用的解析器,这样您就不必自己动手了。

标签: iphone xml parsing sqlite


【解决方案1】:

在抽象级别上(不考虑任何特定平台),您可以将您的 Xml 反序列化为一个对象,然后该对象可以通过 Object-Relational-Mapper 框架持久化到数据库中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 2020-05-04
    相关资源
    最近更新 更多