delphi读取XML示例

procedure TfrmMain.btn1Click(Sender: TObject);
var
  TextXML:IXMLDocument;
  XmlRoot:IXMLNode;
  NodePos:IXMLNode;
  b:string;
  x,y:double;
  LocateInfo:TLocateInfo;
begin
  TextXML:=TXMLDocument.Create(nil);
  TextXML.LoadFromFile('c: esponse.xml');
  XmlRoot:= TextXML.DocumentElement;
  NodePos:=XmlRoot.ChildNodes['slia'].ChildNodes['pos'];
  LocateInfo.Mobile:=NodePos.ChildNodes['msid'].NodeValue;
  LocateInfo.X := NodePos.ChildNodes['pd'].ChildNodes['shape'].ChildNodes['Point'].ChildNodes['coord'].ChildNodes['X'].NodeValue;
  LocateInfo.Y := NodePos.ChildNodes['pd'].ChildNodes['shape'].ChildNodes['Point'].ChildNodes['coord'].ChildNodes['Y'].NodeValue;
  showmessage(b);
end;

  

 

//以下为示例XML文件:

<?xml version="1.0" encoding="gb2312"?> 
<svc_result ver="1.0.0">     
<hdr ver="1.0.0">         
	<sessionid>10587695901453864860</sessionid>     
</hdr>     
<slia ver="1.0.0">         
	<pos>             
		<msid type="MSISDN" enc="ASC">13999991113</msid><!--返回结果的手机号码-->             
		<pd>          
			<time utc_off="+0800">20030721143954</time>                 
			<shape>      
				<Point gid="some_thing" srsName="www.epsg.org#4326">                         
					<coord><!--返回的经纬度--> 
						<X>116.21392</X>                             
						<Y>40.22050</Y>                         
					</coord>                     
				</Point>   
			</shape>            
		</pd>         
	</pos>         
	<msid_status>M_NORMAL</msid_status>         
	<roam_city>010</roam_city>     
</slia> 
</svc_result>

 

你可能感兴趣的:(C++,c,xml,mobile,Delphi)