[英]How to find attribute of root node in touch xml?
NSString *xml = @"<?xml version="1.0" encoding="ISO-8859-15"?>
<ServerDateTime DateRequested="" DateSent="20141013_114855">
<DateTime>20141013_114857</DateTime>
</ServerDateTime>";
In above xml, how to find the attribute value of 'DataSent'? 在上面的xml中,如何查找“ DataSent”的属性值?
I have tried by following, but i didn't get the value. 我已经尝试通过遵循,但我没有得到价值。
CXMLDocument *documentParser = [[CXMLDocument alloc]initWithData:[xml dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
NSArray *arrayResult = [documentParser nodesForXPath:@"//ServerDateTime" error:nil];
for(CXMLElement *element in arrayResult){
NSString *value = [element name];
if ([value isEqualToString:@"ServerDateTime"]) {
NSString *newLastSyncDate = [[element attributeForName:@"DataSent"] stringValue]; //it gives nil..
}
}
You may want to use XPath-queries to search for elements inside a XML. 您可能需要使用XPath查询来搜索XML内的元素。 You have to look up if CXML supports this.
您必须查找CXML是否支持此功能。 Maybe also take a look at this question .
也许也看看这个问题 。
There someone is searching for a given attribute with an XPath-query. 有人正在使用XPath查询来搜索给定的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.