最近需要用delphi与一个公司对接,对方返回过来的数据时widestring格式(内容为xml格式文本)的,我把返回结果赋值到TxlDocument 控件上,但是不知道怎么提取我想要的信息,万望大侠不吝赐教 :-------------------------------------------------------------
返回结果 为:
<?xml version="1.0" encoding="gb2312" standalone="yes"?>
<data version="1.0">
<record operator_code ="1"
operator_password=”123413”
operator_name="超级管理员"/>
<record operator_code ="2"
operator_password=”123413”
operator_name="Test"/>
</data>
--------------------------------------------------------------
获取值得代码如下:
var
SLogginID,sLogginPsw:string;
Nodelist: IXMLNodeList;
attrList: IXMLNodeList;
node: IXMLNode;
begin
……
…… //获取结果,得到结果为变量:Res,类型: WideString XmlMain.XML.Text:= widechartostring(Pwidechar(res)); node := XmlMain.DocumentElement;
Nodelist:=node.ChildNodes.Nodes['record'].ChildNodes; attrList := Nodelist[0].AttributeNodes;
IF attrList[0].NodeName='operator_code' then
SLogginID:=attrList[0].NodeValue;
……
end;
-----------------------------------------
PS:到这些 Node 的地方 就不知道该怎么提取到想要的数据,如operator_code,operator_password 这些数据,我该怎么办?万分感谢!!!!!
返回结果 为:
<?xml version="1.0" encoding="gb2312" standalone="yes"?>
<data version="1.0">
<record operator_code ="1"
operator_password=”123413”
operator_name="超级管理员"/>
<record operator_code ="2"
operator_password=”123413”
operator_name="Test"/>
</data>
--------------------------------------------------------------
获取值得代码如下:
var
SLogginID,sLogginPsw:string;
Nodelist: IXMLNodeList;
attrList: IXMLNodeList;
node: IXMLNode;
begin
……
…… //获取结果,得到结果为变量:Res,类型: WideString XmlMain.XML.Text:= widechartostring(Pwidechar(res)); node := XmlMain.DocumentElement;
Nodelist:=node.ChildNodes.Nodes['record'].ChildNodes; attrList := Nodelist[0].AttributeNodes;
IF attrList[0].NodeName='operator_code' then
SLogginID:=attrList[0].NodeValue;
……
end;
-----------------------------------------
PS:到这些 Node 的地方 就不知道该怎么提取到想要的数据,如operator_code,operator_password 这些数据,我该怎么办?万分感谢!!!!!
你去获取子节点当然没有东西了
详细操作请参考:
Delphi 与 XML
var
AVar:OleVariant;
begin
Result:=False;
if AXMLNode=nil then exit; AVar:=AXMLNode.Attributes['Name'];
if not VarIsNull(AVar) then Name:=AVar;
AVar:=AXMLNode.Attributes['Hint'];
if not VarIsNull(AVar) then Hint:=AVar;
AVar:=AXMLNode.Attributes['LinkedURL'];
if not VarIsNull(AVar) then LinkedURL:=AVar;
AVar:=AXMLNode.Attributes['EnableHovered'];
if not VarIsNull(AVar) then EnableHovered:=AVar;
AVar:=AXMLNode.Attributes['EnableClick'];
if not VarIsNull(AVar) then EnableClick:=AVar;
AVar:=AXMLNode.Attributes['PosX'];
if not VarIsNull(AVar) then PosX:=AVar;
AVar:=AXMLNode.Attributes['PosY'];
if not VarIsNull(AVar) then PosY:=AVar;
AVar:=AXMLNode.Attributes['Width'];
if not VarIsNull(AVar) then Width:=AVar;
AVar:=AXMLNode.Attributes['Height'];
if not VarIsNull(AVar) then Height:=AVar;
AVar:=AXMLNode.Attributes['Visible'];
if not VarIsNull(AVar) then Visible:=AVar;
AVar:=AXMLNode.Attributes['ShowHint'];
if not VarIsNull(AVar) then ShowHint:=AVar;
AVar:=AXMLNode.Attributes['EnableHint'];
if not VarIsNull(AVar) then EnableHint:=AVar;
AVar:=AXMLNode.Attributes['HintInterval'];
if not VarIsNull(AVar) then HintInterval:=AVar;
Result:=True;end;