急问!!!Delphi中的TXMLDocument控件如何实现查询节点的功能!!! (100分)

  • 主题发起人 主题发起人 netexplorer
  • 开始时间 开始时间
N

netexplorer

Unregistered / Unconfirmed
GUEST, unregistred user!
TXMLDocument是delphi自带的操纵xml的控件,
但是我在其中没有找到DOM模型中规定的Node.SelectNodes(xpath)函数,
这样就不能在xml文件中查找指定的节点。
请问有什么方法解决吗?
有什么变通的办法可以实现SelectNodes函数的功能,
最好不要重新自己封装一遍msxml库,累死。
谢谢,急!!
 
谢谢各位答复阿!!
up有分!!
 
function TXmlDocManager.GetDestTable(TableName:string): TdestTable;
var
tablenode: IXMLnode;
node: Ixmlnode;
I, j: integer;
begin
node:=XmlDocu.DocumentElement;
node:=node.ChildNodes['Tables'];
for i:=0 to node.ChildNodes.Count-1do
begin
tablenode:=node.ChildNodes;
if tablenode.Attributes['tableName']=TableName then
begin

Result.tablename:=tablenode.AttributeNodes['tableName'].Text;
Result.Description := tablenode.AttributeNodes['description'].Text;
//sourcetable
Result.Source.tableName :=tablenode.ChildNodes['sourceTable'].AttributeNodes['tableName'].Text ;
Result.Source.description :=tablenode.ChildNodes['sourceTable'].AttributeNodes['description'].Text ;
Result.Source.where :=tablenode.ChildNodes['sourceTable'].AttributeNodes['where'].Text ;
//links
for j:=0 to tablenode.ChildNodes['Links'].ChildNodes.Count-1do
begin
setLength(Result.links,length(Result.links)+1);
Result.links[j].TableName :=tablenode.ChildNodes['Links'].childnodes[j].AttributeNodes['tableName'].Text ;
Result.links[j].Description :=tablenode.ChildNodes['Links'].childnodes[j].AttributeNodes['description'].Text ;
Result.links[j].relation :=tablenode.ChildNodes['Links'].childnodes[j].AttributeNodes['relation'].Text ;
end;
break;
end;
end;

procedure TXmlDocManager.SetDestDatabaseConnectionStr(Provider,DestServerName,
DestCatalog, DestUserName, DestPassword: string);
var
node,subnode: IXMLnode;
begin
node := XmlDocu.DocumentElement;
subnode := node.ChildNodes['DestDatabase'];
subnode.SetAttribute('provider', Provider);
subnode.SetAttribute('serverName', DestserverName);
subnode.SetAttribute('catalog', DestCatalog);
subnode.SetAttribute('userName', DestUserName);
subnode.SetAttribute('password', DestPassword);
Changed:=True;
end;

procedure TXmlDocManager.GetDestDatabaseConnectionStr(var Provider,DestServerName,
DestCatalog, DestUserName, DestPassword: string);
var
node,subnode: IXMLnode;
begin
node := XmlDocu.DocumentElement;
subnode := node.ChildNodes['DestDatabase'];
Provider:= subnode.AttributeNodes['provider'].Text;
DestServerName := subnode.AttributeNodes['serverName'].Text;
DestCatalog := subnode.AttributeNodes['catalog'].Text;
DestUserName := subnode.AttributeNodes['userName'].Text;
DestPassword := subnode.AttributeNodes['password'].Text;
end;
end;

 
兄台,先谢谢你了!!
能否简单说明一下这个代码怎么用,谢谢!
 
后退
顶部