我正在尝试解析XML,但是XML代码的引用会产生问题并且无法运行。有没有办法调用这个xml <table border="0" cellpadding="0" cellspacing="0" width="392">
,如代码所示?
提前感谢。
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ( [elementName isEqualToString:@" table border="0" cellpadding="0" cellspacing="0" width="392" "] ) {
[[self titleArray] addObject:[self currentStringValueTitle]];
}
[self setCurrentStringValueTitle:nil];
我想阅读这个源页面
<body>
<table border="0" cellpadding="0" cellspacing="0" width="392">
<tr>
<td width="392" class="hdlnType2">
<div
style="FONT-WEIGHT: bold; FONT-SIZE: 1.12em; FLOAT: left; ">
<!-- enable chat -->
I wanna print this text....
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</body>
答案 0 :(得分:0)
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"table"]){
NSString *border=[attributeDict valueForKey:@"border"];
NSString *cellpadding=[attributeDict valueForKey:@"cellpadding"];
NSString *cellspacing=[attributeDict valueForKey:@"cellspacing"];
NSString *width=[attributeDict valueForKey:@"width"];
}
if([elementName isEqualToString:@"div"]){
//fetch values here like did for table tag from attributedDict
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
//NSLog(@"Processing Value: %@", currentElementValue);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"div"]) {
NSLog(currentElementValue,nil);
}
[currentElementValue release];
currentElementValue = nil;
}
任何标签的参数都将被解析并保存到didStartElement方法的attributionDict参数中