0

我必须在我的图书应用程序中阅读和显示多个字符对话。我打算以以下格式在 XML 中存储字符对话数据:

<?xml version="1.0" encoding="UTF-8"?>
<Pages>
    <Page Id="P1">
        <T>Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.</T>
        <A>This is audio file location.This is audio file location.This is audio file location.</A>
        <Dlg>
            <Dlg Id="C1D1" P="L" X="" Y="" W="" H="">
                <T>This is Character 1 Dialogue 1.This is Character 1 Dialogue 1.</T>
                <A>This is audio file location.This is audio file location.</A>
            </Dlg>
            <Dlg Id="C1D2" P="R" X="" Y="" W="" H="">
                <T>This is Character 1 Dialogue 2.This is Character 1 Dialogue 2.</T>
                <A>This is audio file location.This is audio file location.</A>
            </Dlg>
            <Dlg Id="C2D1" P="L" X="" Y="" W="" H="">
                <T>This is Character 2 Dialogue 1.This is Character 2 Dialogue 1.</T>
                <A>This is audio file location.This is audio file location.</A>
            </Dlg>
        </Dlg>
    </Page>
    <Page Id="P2">
        <T>Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.</T>
        <A>This is audio file location.This is audio file location.This is audio file location.</A>
        <Dlg>
            <Dlg Id="C1D1" P="R" X="" Y="" W="" H="">
                <T>This is Character 1 Dialogue 1.This is Character 1 Dialogue 1.</T>
                <A>This is audio file location.This is audio file location.</A>
            </Dlg>
            <Dlg Id="C2D1" P="L" X="" Y="" W="" H="">
                <T>This is Character 2 Dialogue 1.This is Character 2 Dialogue 1.</T>
                <A>This is audio file location.This is audio file location.</A>
            </Dlg>
            <Dlg Id="C2D2" P="R" X="" Y="" W="" H="">
                <T>This is Character 2 Dialogue 2.This is Character 2 Dialogue 2.</T>
                <A>This is audio file location.This is audio file location.</A>
            </Dlg>
        </Dlg>
    </Page>
</Pages>

从 XML 结构中可以看出,会有多个页面,每个页面会有多个字符,每个字符会有多个对话。此 XML 的大小可能约为 250 KB(不确定对于 iPhone/iPad 是否太大)。我打算使用 GDataXML 来解析这个 XML 并存储为以下模型对象:

#import <Foundation/Foundation.h>

typedef enum {
    Left,
    Right
} DialoguePosition;

@interface Dialogue : NSObject{
    NSString *_id;
    int _frameX;
    int _frameY;
    int _frameWidth;
    int _frameHeight;
    DialoguePosition _dialoguePosition;
    NSString *_dialogueText;
    NSString *_dialogueAudioLocation;
}
@property (nonatomic, copy) NSString *id;
@property (nonatomic, assign) int frameX;
@property (nonatomic, assign) int frameY;
@property (nonatomic, assign) int frameWidth;
@property (nonatomic, assign) int frameHeight;
@property (nonatomic, assign) DialoguePosition dialoguePosition;
@property (nonatomic, copy) NSString *dialogueText;
@property (nonatomic, copy) NSString *dialogueAudioLocation;

- (id)initWithName:(NSString *)id frameX:(int)frameX frameY:(int)frameY frameWidth:(int)frameWidth frameHeight:(int)frameHeight dialoguePosition:(DialoguePosition)dialoguePosition dialogueText:(NSString *)dialogueText dialogueAudioLocation:(NSString *)dialogueAudioLocation;

@end

我应该使用属性列表而不是 XML 还是 XML 应该没问题?我需要通过传递页面 ID 和对话 ID 轻松快速地访问对话。为了实现这一点,我应该将 Dialogue 模型对象存储在 NSDictionary 中还是应该采用其他更好的方法。我将不胜感激您对我应该采取的方法的建议。

4

0 回答 0