在解析 xml 时,在一些字行结束后没有完整的数据,阅读更多
以下三个代码位于一个 html 页面中,但为了更好地理解,我仍然这样做了。
我正在使用 NSXMLParser 将其解析到我的 iPhone 应用程序中。问题是它的解析直到<Style>
下面然后它停止从文本解析并完全忽略文本下面的数据!!!
<head>
<title>North Mobile County Middle School: Latest News > "1st Annual NMCK-8 Christmas Music Program"</title>
<META HTTP-EQUIV="X-UA-COMPATIBLE" CONTENT="IE=EmulateIE9">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="imagetoolbar" content="no">
<script type="text/javascript" src="JavaScripts.js"></script>
<script type="text/javascript" src="JavaScripts/NiceTitles.js"></script>
<style type="text/css">
我正在拆分代码以便更好地理解
!--
body {
margin:0; padding:0;
background: #fff;}
body, td {
font: normal 13px "Trebuchet MS", Arial, Helvetica, sans-serif;
color:#333;}
/***********************************************/
/* Links
/***********************************************/
a:link, a:visited {
color: #CD0000;
text-decoration: none;}
a:hover, a:active {
color: #06f;
text-decoration: underline;}
img {border: 0;}
我正在拆分代码以便更好地理解
#MainPageArea {padding: 0 15px 15px 15px}
</style>
<link href="http://images.pcmac.org/SiSFiles/Schools/AL/MobileCounty/NorthMobileMiddle/styles.css" rel="stylesheet" type="text/css">
<!--[if lt IE 7]>
<link href="Common/CommonIncludes/Template11/IEStyles.css" rel="stylesheet" type="text/css">
<![endif]-->
<link rel="Shortcut Icon" type="image/ico" href="http://images.pcmac.org/SiSFiles/Schools/AL/MobileCounty/NorthMobileMiddle/images/favicon.ico" />
</head>
<body class="DefaultPage">
<table align="center" cellpadding="0" cellspacing="0" width="986" border="0" id="PageWrapper">
<tr>
<td valign="top">
<div id="Header">
我正在使用如下代码:
-(id) loadHtmlByURL:(NSString *)urlString
{
NSURL *url = [NSURL URLWithString:urlString];
NSData *nsData = [[NSData alloc] initWithContentsOfURL:url];
elementArray = [[NSMutableArray alloc] init];
parser = [[NSXMLParser alloc] initWithData:nsData];
parser.delegate = self;
[parser parse];
currentHTMLElement = [HtmlElement alloc];
return self;
}
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(@"%@",elementname);
currentHTMLElement = [[HtmlElement alloc] autorelease];
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(@"%@",elementname);
if ([elementname isEqualToString:@"head"])
{
currentHTMLElement.tag = elementname;
currentHTMLElement.value = currentNodeContent;
[elementArray addObject:currentHTMLElement];
currentHTMLElement = nil;
currentNodeContent = nil;
// NSLog(@"x%@",elementArray);
}
我能知道我被击中了吗