从XML格式化中分割字符串 [英] Spliting a string from XML formate

查看:102
本文介绍了从XML格式化中分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用evernote api与evernote共享一张便条,它是成功的,它将笔记上传到evernote。但是当我从evernote下载笔记到我的应用程序时,它给了我xml formate.my代码中的注释发送便笺是。
在我的按钮中点击
{

i am sharing a note to evernote by using the evernote api,it is sucess,it uploade the note to evernote.but when i download the Note from the evernote to my application it is giving me note in xml formate.my code for sending note is . IN my button click {

 EDAMNote * note = [[[EDAMNote alloc] init]autorelease];
note.title = @"Appname";
NSMutableString *str = [[NSMutableString alloc] initWithString:@"NOTES:"]; 
    for (int i = 0; i<[appDelegate.notesArray count]; i++) { 
        NSString * aString = [[NSString alloc] initWithString:[appDelegate.notesArray objectAtIndex:i]] ;
        NSString * ENML= [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note>%@",aString];
ENML = [NSString stringWithFormat:@"%@%@", ENML, @"</en-note>"];
    NSLog(@"%@", ENML);

    // Adding the content & resources to the note
    [note setContent:ENML];
    }

它将发送 aString 正确到evernote。
和我的Downloding代码是

it will send the value of aString correctly to evernote. and my Downloding code is

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Load the EDAMNote object that has guid we have stored in the object
    EDAMNote * note = [(Evernote *)[Evernote sharedInstance] getNote:guid];
// Changing the navigation title & the content block
    noteNavigation.topItem.title = [note title];
    //adding note to textview 
    noteContent.text = [note content];

    // Adding a back button to close the windows
    UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(goBack:)];

    UINavigationItem *item = [[[UINavigationItem alloc] init] autorelease];
    item.leftBarButtonItem = doneButton;
    item.hidesBackButton = YES;
    [noteNavigation pushNavigationItem:item animated:NO];
    noteNavigation.topItem.title = [note title];


}

它正确下载,但它显示了注释像这样

it downloeds correctly but it shows the note with like this

<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note> then our noteeeee in this areaaa>

但我只希望然后我们在这个区域内的记录在textview.how中过滤这个?

but i want this only then our noteeeee in this areaaa in the textview.how to filter this?

推荐答案

一种方法是使用NSXMLParser。如果您唯一关心的是那一行,那么编写解析器委托就很容易了。所有你需要的是:

One way to do that would be to use NSXMLParser. If the only thing you care about is that one line, then it'll be easy to write your parser delegate. All you'll need are:


  • 一个变量(使用NSMutableString)来保存文本,可能叫做 noteText

a -parser:didStartElement:namespaceURI:qualifiedName:attributes:当您获得< en-note> 标记

a -parser:foundCharacters:将找到的字符添加到 noteText的方法

a -parser:foundCharacters: method to add found characters to noteText

a -parser:didEndElement:namespaceURI:qualifiedName:使用<$ c执行某些操作的方法$ c> noteText 获得< / en-note> 代码

这篇关于从XML格式化中分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆