解析XML時遇到問題。 我設法進入「TXMLDocument」,但它不適用於Android。Android中的XML解析,IXMLDOMDocument
如何獲取字段值? 我需要9240-221 我需要的價值:「9240-221」
我沒有在谷歌找到如何做到這一點(也沒有找到關於如何使用的IXMLDOMDocument工作手冊)。
代碼:
uses ComObj, MSXML;
procedure TForm2.Button1Click(Sender: TObject);
var
xml: IXMLDOMDocument;
node: IXMLDomNode;
nodes_row, nodes_se: IXMLDomNodeList;
i, j: Integer;
url: string;
begin
// put url or file name
//url := 'https://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.xml?prox=32.791288%2C-17.045887&mode=retrieveAddresses&maxresults=1&gen=8&app_id=ZHsaRDKOhKQKjKOba0cS&app_code=RPlNCmcST6RICWUMk2OzYQ';
xml := CreateOleObject('Microsoft.XMLDOM') as IXMLDOMDocument;
xml.async := False;
//xml.load(url); // or use loadXML to load XML document using a supplied string
xml.loadXML
(
'<ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4">'+
'<Response>'+
'<MetaInfo>...</MetaInfo>'+
'<View xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:SearchResultsViewType"> '+
'<ViewId>0</ViewId>'+
'<Result>'+
'<Relevance>1.0</Relevance>'+
'<Distance>-1996.0</Distance>'+
'<Direction>358.6</Direction>'+
'<MatchLevel>city</MatchLevel>'+
'<MatchQuality>...</MatchQuality>'+
'<Location>'+
'<LocationId>NT_yT.xGXLRj-bHQLe8aMmP2A</LocationId>'+
'<LocationType>area</LocationType>'+
'<DisplayPosition>...</DisplayPosition>'+
'<MapView>...</MapView>'+
'<Address>'+
'<Label>São Vicente, Portugal</Label>'+
'<Country>PRT</Country>'+
'<County>Ilha da Madeira</County>'+
'<City>São Vicente</City>'+
'<PostalCode>9240-221</PostalCode> '+
'<AdditionalData key="CountryName">Portugal</AdditionalData>'+
'<AdditionalData key="CountyName">Ilha da Madeira</AdditionalData>'+
'</Address>'+
'<MapReference>...</MapReference>'+
'</Location> '+
'</Result>'+
'</View>'+
'</Response>'+
'</ns2:Search>'
);
if xml.parseError.errorCode <> 0 then
raise Exception.Create('XML Load error:' + xml.parseError.reason);
nodes_row := xml.selectNodes('/ns2');
for i := 0 to nodes_row.length - 1 do
begin
node := nodes_row.item[i];
showmessage('phrase=' + node.selectSingleNode('ViewId').text);
nodes_se := node.selectNodes('.....');
for j := 0 to nodes_se.length - 1 do
begin
node := nodes_se.item[j];
end;
showmessage('--------------');
end;
end;
的IXMLDOMDocument是Windows XML解析器的接口對象(請參閱https://msdn.microsoft.com/en-us/library/windows/desktop/dd892951(v=vs.85).aspx)。你爲什麼期望在Android上使用它? – MartynA
在「Embarcadero公司RadStudio 10.1Berlin - 德爾福」編譯窗戶時,我能得到「郵編」使用「TXMLDocument的」,但在Android上做當 「X:= TXMLDocument.Create(個體經營);在運行時,它給出了一個錯誤,我不能得到的值 所以我試圖找出另一種方式來獲得它 –
@MartynA:。OmniXML廠商是跨平臺 – whosrdaddy