如何读取这样的xml文件(100分)

热水

Unregistered / Unconfirmed
GUEST, unregistred user!
<table1>
<record1>
<field1>..</field1>
<field2>..</field2>
</record1>
<record2>
....
<record2>
</table1>
<table2>
......
</table2>
能否提供生成和读取的代码范例。
 
File->New->Others->XML Data Binding
保证帮你完成的好好的.
 
我的目的是做一个“企业资料报送”,用户在界面输入内容后,把界面内容保存为一个
临时文件temp.xml中,当然每次系统进去后能自动从temp.xml中读出内容显示界面。最终实现
客户报送的temp.xml文件能发到其总公司主系统中(jsp开发环境)实现导入数据库中。
to LeeChange:能给一段示例代码吗。
 
请提供一个完整的XML文件.
结构要全,记录两三条就够了.
 
如:
<EnterpriseInfo>
<record>
<name>中华实业公司</name>
<address>北京市海淀区</address>
<phone>010-64687802</phone>
</record>
<record>
<name>中华实业公司2</name>
<address>北京市宣武区</address>
<phone>010-63687802</phone>
</record>
</EnterpriseInfo>
<ProjInfo>
<record>
<LoanSum>123.45</LoanSum>
<loanMonths>12</loanMonths>
</record>
</ProjInfo>
 
还未动手,但有一点建议:
最好有根结点,上两个作为两个文件保存.
 
我用LeeChange讲的方法"file/new/others/ML Data Binding "做了一个试验,估计可以解决了。
谢谢LeeChange.
 
unit EnterpiseUnit;
interface
uses xmldom, XMLDoc, XMLIntf;
type
{ Forward Decls }
IXMLEnterpriseInfoType = interface;
IXMLRecordType = interface;
{ IXMLEnterpriseInfoType }
IXMLEnterpriseInfoType = interface(IXMLNodeCollection)
['{453A2D6F-2EB1-463A-81C1-575F1A16327F}']
{ Property Accessors }
function Get_Record_(Index: Integer): IXMLRecordType;
{ Methods &amp;
Properties }
function Add: IXMLRecordType;
function Insert(const Index: Integer): IXMLRecordType;
property Record_[Index: Integer]: IXMLRecordType read Get_Record_;
default;
end;

{ IXMLRecordType }
IXMLRecordType = interface(IXMLNode)
['{659A02C4-5603-466C-8D6A-80ECCB8F5CA3}']
{ Property Accessors }
function Get_Name: WideString;
function Get_Address: WideString;
function Get_Phone: WideString;
procedure Set_Name(Value: WideString);
procedure Set_Address(Value: WideString);
procedure Set_Phone(Value: WideString);
{ Methods &amp;
Properties }
property Name: WideString read Get_Name write Set_Name;
property Address: WideString read Get_Address write Set_Address;
property Phone: WideString read Get_Phone write Set_Phone;
end;

{ Forward Decls }
TXMLEnterpriseInfoType = class;
TXMLRecordType = class;
{ TXMLEnterpriseInfoType }
TXMLEnterpriseInfoType = class(TXMLNodeCollection, IXMLEnterpriseInfoType)
protected
{ IXMLEnterpriseInfoType }
function Get_Record_(Index: Integer): IXMLRecordType;
function Add: IXMLRecordType;
function Insert(const Index: Integer): IXMLRecordType;
public
procedure AfterConstruction;
override;
end;

{ TXMLRecordType }
TXMLRecordType = class(TXMLNode, IXMLRecordType)
protected
{ IXMLRecordType }
function Get_Name: WideString;
function Get_Address: WideString;
function Get_Phone: WideString;
procedure Set_Name(Value: WideString);
procedure Set_Address(Value: WideString);
procedure Set_Phone(Value: WideString);
end;

{ Global Functions }
function GetEnterpriseInfo(Doc: IXMLDocument): IXMLEnterpriseInfoType;
function LoadEnterpriseInfo(const FileName: WideString): IXMLEnterpriseInfoType;
function NewEnterpriseInfo: IXMLEnterpriseInfoType;
implementation
{ Global Functions }
function GetEnterpriseInfo(Doc: IXMLDocument): IXMLEnterpriseInfoType;
begin
Result :=do
c.GetDocBinding('EnterpriseInfo', TXMLEnterpriseInfoType) as IXMLEnterpriseInfoType;
end;
function LoadEnterpriseInfo(const FileName: WideString): IXMLEnterpriseInfoType;
begin
Result := LoadXMLDocument(FileName).GetDocBinding('EnterpriseInfo', TXMLEnterpriseInfoType) as IXMLEnterpriseInfoType;
end;

function NewEnterpriseInfo: IXMLEnterpriseInfoType;
begin
Result := NewXMLDocument.GetDocBinding('EnterpriseInfo', TXMLEnterpriseInfoType) as IXMLEnterpriseInfoType;
end;

{ TXMLEnterpriseInfoType }
procedure TXMLEnterpriseInfoType.AfterConstruction;
begin
RegisterChildNode('record', TXMLRecordType);
ItemTag := 'record';
ItemInterface := IXMLRecordType;
inherited;
end;

function TXMLEnterpriseInfoType.Get_Record_(Index: Integer): IXMLRecordType;
begin
Result := List[Index] as IXMLRecordType;
end;

function TXMLEnterpriseInfoType.Add: IXMLRecordType;
begin
Result := AddItem(-1) as IXMLRecordType;
end;

function TXMLEnterpriseInfoType.Insert(const Index: Integer): IXMLRecordType;
begin
Result := AddItem(Index) as IXMLRecordType;
end;

{ TXMLRecordType }
function TXMLRecordType.Get_Name: WideString;
begin
Result := ChildNodes['name'].Text;
end;

procedure TXMLRecordType.Set_Name(Value: WideString);
begin
ChildNodes['name'].NodeValue := Value;
end;

function TXMLRecordType.Get_Address: WideString;
begin
Result := ChildNodes['address'].Text;
end;

procedure TXMLRecordType.Set_Address(Value: WideString);
begin
ChildNodes['address'].NodeValue := Value;
end;

function TXMLRecordType.Get_Phone: WideString;
begin
Result := ChildNodes['phone'].Text;
end;

procedure TXMLRecordType.Set_Phone(Value: WideString);
begin
ChildNodes['phone'].NodeValue := Value;
end;

end.

长吗?不是很长吧.
 
如果要把所有的表内容放在同一个xml文件中用LeeChange讲的方法就没办法实现了。
 
顶部