NSXMLElement stringValue 的妙用 想了很多方法去除<![CDATA[ ]]>无果,突然发现stringValue管用
NSXMLElement *msgXml = [[DDXMLElement alloc] initWithXMLString:message.stringValue error:nil];//message.stringValue已经解析好了转义的符号
//IM平台的msg_content节点
NSXMLElement *immsg_contentXml = [msgXml elementForName:@"msg_content"];
//PA平台的msg_content节点
NSXMLElement *pamsg_contentXml = [[DDXMLElement alloc] initWithXMLString:immsg_contentXml.stringValue error:nil];//immsg_contentXml.stringValue已经解析去掉了“<![CDATA[ ]]>”
int mediaType = [[[pamsg_contentXml elementForName:@"media_type"] stringValue]intValue];
另外
//XML转义特殊字符
- (NSString *)stringByEncodingXMLEntity
{
NSString *tempStr;
tempStr = [self stringByReplacingOccurrencesOfString:@"\"" withString:@"""];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@">" withString:@">"];
return tempStr;
}
//XML还原特殊字符
- (NSString *)stringByDecodingXMLEntity
{
NSString *tempStr;
tempStr = [self stringByReplacingOccurrencesOfString:@""" withString:@"\""];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
tempStr = [tempStr stringByReplacingOccurrencesOfString:@">" withString:@">"];
return tempStr;
}