2012-02-13 74 views
-2

我有一個所謂的內容是[note content];持有XML元素串hello world 的XML元素就像如何解析XML

<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note>hello world </en-note>" 

我試過的NSXMLParser解析這一點,但沒有luck.how我可以解析[note content];並分開那個字符串?有沒有其他的方式來分隔這個字符串?

+0

@rckoenes ...謝謝爲鏈接..我會用這個進一步愚蠢的問題....也許它應該是你的答案... – 2012-02-13 11:36:43

+0

重複問題http://stackoverflow.com/q/6990236/468724 – 2012-02-13 11:41:38

+0

@InderKumarRathore我把NSString * EN-注;我得到的錯誤是 - 符號不能是一個字符串。我怎樣才能解析這個字符串在XML中。 – stackiphone 2012-02-13 11:50:46

回答

2

嘿,你可以使用XML解析或上述特定字符串,您可以使用下面的代碼(如你要求的其他方式)

NSString *str = @"<\?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note>hello world </en-note>"; 
NSArray *arr = [str componentsSeparatedByString:@"<en-note>"]; 
if ([arr count] == 2) { 
    str = [arr objectAtIndex:1]; 
    str = [str stringByReplacingOccurrencesOfString:@"</en-note>" withString:@""]; 
} 
NSLog(@"%@",str); 
+0

謝謝yarrrr,我是新來的XML解析。我檢查。 – stackiphone 2012-02-13 11:56:10

+0

,很好+10000000對你很有幫助。謝謝yarrrrr.it工作正常。我把NSString * str = [注意內容]; NSArray * arr = [str componentsSeparatedByString:@「」]; if([arr count] == 2)str = [arr objectAtIndex:1]; str = [str stringByReplacingOccurrencesOfString:@「」withString:@「」]; } NSLog(@「%@」,str); noteContent.text = str; – stackiphone 2012-02-13 12:00:45

+0

但嘗試學習XML解析..這裏是一個很好的圖書館和教程http://www.tbxml.co.uk/TBXML/TBXML_Free.html – 2012-02-13 14:15:30