由於在實際的iPhone上給定了NSXML的限制,因此我使用了TouchXml。無論如何,我剛剛開始接觸的Objective-C,我來自一個C#背景,感覺就像學習的東西new..anyhow ..這裏是我的xml文件...使用TouchXML獲取可可元素的值
<?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,正則表達式非常容易獲得。
UPDATE2:我已經想出瞭如何使用RegexKitLite for regex。
所以現在的問題是,我如何從FundValue裏面得到「7800」,現在它是一個大字符串。我已經通過使用NSLog寫入它來證實我在我的NSString中有它。
感謝您的答覆,我得到一個崩潰有以下異常消息:。 [CXMLElement isEqualToString :]:發送到實例的無法識別的選擇器 – kd7 2009-02-09 03:33:32