由于 NSXML 在实际 iPhone 上的给定限制,我正在使用 TouchXml。无论如何,我刚刚开始使用 Objective-C,我来自 C# 背景,并且想学习一些新的东西..无论如何.. 这是我的 xml 文件...
<?xml version="1.0" encoding="utf-8"?>
<FundInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/webservices">
<FundsReleaseDate>2009-02-11T00:00:00</FundsReleaseDate>
<FundValue>7800</FundValue>
<FundShares>1000</FundShares>
</FundInfo>
我正在尝试获得 7800,即 FundValue。有人能指出我正确的方向吗,我正在使用 TouchXml CXMLDocument 并且 myParser 是 CXMLDocument 类型,我已经尝试过
NSArray *nodes = [myParser nodesForXPath:@"//FundInfo" error:&err];
基本上节点评估为零
if ([nodes count] > 0 ) {
amount = [nodes objectAtIndex:1];
}
更新 1:我已经放弃使用 XPath 进行解析,并将其替换为 NSURLRequest,所以现在我将整个 XML 放在一个字符串中,但我对 Objective-C 的粗鲁介绍仍在继续……我刚刚意识到我对.NET BCL,Regex 之类的东西很容易获得。
UPDATE2:我已经弄清楚如何使用 RegexKitLite 进行正则表达式。
所以现在的问题是,我如何从 FundValue 中得到“7800”,它现在是一个大字符串。我已经通过使用 NSLog 编写它来确认我在我的 NSString 中有它。