J
jlcsx
Unregistered / Unconfirmed
GUEST, unregistred user!
由于本人没有涉及过XML,现需要从XML文件中读取数据写如到数据库中,
请各位高手指点:
XML文件格式:
======================
<?xml version="1.0" encoding="gb2312" ?>
- <orderlist>
- <order>
<orderid>GS080402-000051</orderid>
<userinfo />
<address />
<phone>13758722177</phone>
- <detail>
<item price="15.00">瑶柱水蒸蛋</item>
<item price="16.00">川烧茄子</item>
<item price="18.00">葱爆二样</item>
</detail>
</order>
</orderlist>
================================
我采用: XMLDocument的控件,读取,
procedure TForm1.Button1Click(Sender: TObject);
var
Clinic: IXMLNode;
begin
XMLDocument1.Active := true;
Clinic := XMLDocument1.DocumentElement.ChildNodes[0];
Memo1.Lines.Clear;
Memo1.Lines.Add(Clinic.ChildNodes['orderid'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['userinfo'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['address'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['phone'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['detail'].Text);
end;
但如何读取子字节点的数据:
子节点如下:[red][/red][black][/black]
- <detail>
<item price="15.00">瑶柱水蒸蛋</item>
<item price="16.00">川烧茄子</item>
<item price="18.00">葱爆二样</item>
</detail>
请各位高手指点:
XML文件格式:
======================
<?xml version="1.0" encoding="gb2312" ?>
- <orderlist>
- <order>
<orderid>GS080402-000051</orderid>
<userinfo />
<address />
<phone>13758722177</phone>
- <detail>
<item price="15.00">瑶柱水蒸蛋</item>
<item price="16.00">川烧茄子</item>
<item price="18.00">葱爆二样</item>
</detail>
</order>
</orderlist>
================================
我采用: XMLDocument的控件,读取,
procedure TForm1.Button1Click(Sender: TObject);
var
Clinic: IXMLNode;
begin
XMLDocument1.Active := true;
Clinic := XMLDocument1.DocumentElement.ChildNodes[0];
Memo1.Lines.Clear;
Memo1.Lines.Add(Clinic.ChildNodes['orderid'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['userinfo'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['address'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['phone'].Text);
Memo1.Lines.Add(Clinic.ChildNodes['detail'].Text);
end;
但如何读取子字节点的数据:
子节点如下:[red][/red][black][/black]
- <detail>
<item price="15.00">瑶柱水蒸蛋</item>
<item price="16.00">川烧茄子</item>
<item price="18.00">葱爆二样</item>
</detail>