[英]How to check the the xml tag string?
嗨,我正在使用以下xml是服務器上的xml。
<message xmlns="jabber:client" to="91957@ip-148" id="A2EFL-1435" from="9176@ip-148"><x xmlns="jabber:x:event"><composing/><id>A2EFL-1434</id></x></message>
現在我需要檢查xml是否具有composing
元素。並且我沒有使用任何xml委托。 沒有為XML使用委托方法的任何可能性
NSXMLElement *events = [message elementForName:@"x"];
NSString *eventString=[[message elementForName:@"x"] stringValue];
if (![eventString isEqualToString:@""]) {
NSString *composingString=[[events elementForName:@"composing"] stringValue];
if ([composingString isEqualToString:@""]||[composingString isEqualToString:@"nil"]) {}
但是我需要檢查xml標記不值
您只需要使用字符串操作即可。 檢查一下。
NSRange rangeValue = [xmlString rangeOfString:@"<composing>" OR @"<composing/>" OR options:NSCaseInsensitiveSearch];
if (rangeValue.length > 0){
NSLog(@"Tag is present");
}
else {
NSLog(@"Tag is not present");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.