0

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];
    }

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>

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

skolima
  • 31,963
  • 27
  • 115
  • 151
stackiphone
  • 1,245
  • 3
  • 19
  • 41

3 Answers3

1

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:

  • a variable (use an NSMutableString) to hold the text, perhaps called noteText

  • a -parser:didStartElement:namespaceURI:qualifiedName:attributes: method to clear noteText when you get the <en-note> tag

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

  • a -parser:didEndElement:namespaceURI:qualifiedName: method to do something with noteText when it gets a </en-note> tag

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • my problem is i get the xml content through string [note content] and [textview.text set content : [note content]]; – stackiphone Feb 13 '12 at 07:14
  • @stackiphone If that's a problem, why are you doing that? However you get the XML, you can still parse it with NSXMLParser or libXML2. – Caleb Feb 13 '12 at 07:19
  • i put aboe code for parsing but nothing happens,please see my edit – stackiphone Feb 13 '12 at 09:02
0

You can implement the NSXMLParserDelegate and parse de xml. You can find many samples around like this or this

Community
  • 1
  • 1
Luis
  • 1,282
  • 1
  • 11
  • 25
0

Apple has two built in solutions for parsing XML data on the iphone. The objective-c implementation of an XML parser called NSXMLParser and a C based implementation of an XML parser called libXML2.

http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

http://developer.apple.com/iphone/library/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/iPhoneOSTechnologies/iPhoneOSTechnologies.html

Edit:

This article shows you how to parse XML using the NSXMLParser

http://www.codeproject.com/Articles/248883/Objective-C-Fundamentals-NSXMLParser

Fraser
  • 15,275
  • 8
  • 53
  • 104