read xml demo

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE person SYSTEM "test.dtd">
<Root>
    <Conn>
        <dbtype>mssql</dbtype>
        <dbalis>testinfo</dbalis>
        <userid>sa</userid>
        <password>123</password>
    </Conn>

    <module id="test">
    <code>
        <![CDATA[
        select * from jg order by sn
        ]]>"
</code>
    </module>

    <module id="testid">
    <sql> <![CDATA[<a href=“http://www.baidu.com”>出山</a> ]]></sql>
    <![CDATA[
        select * from jg where id>=#param.id order by sn
        ]]>
    </module>

    <module id="test1">
        <sql> <![CDATA[<a href=“http://www.baidu.com”>出山</a> ]]></sql>
    <![CDATA[
        insert into jg(jid,jname,cname) valeus(#param.jid, #param.jname, #param.cname)
        ]]>
    </module>
 
==============================================
 

var
mFileName: string;
mDocument: IXMLDocument;
mMainNode: IXMLNode;
mStrList: TStringList;
begin
mFileName := ExtractFileDir(ParamStr(0)) + '\' + xmlfile;
if not FileExists(mFileName) then
Exit;
mDocument := TXMLDocument.Create(nil);
mDocument.LoadFromFile(mFileName);
mMainNode := mDocument.DocumentElement;
mStrList := TStringList.Create;
ReadXMlNode(mStrList, mMainNode);
memo1.Lines.Text := mStrList.Text;
mStrList.Free;

========================================
 
 
 
 

nodeList,mNodeList: IXMLNodeList;
mNodeName: string;
mTmpStr,msg,code,counts: string;
begin
mTmpStr := '';
if not ANode.HasChildNodes then // Èç¹û mNode ûÓÐ×Ó½Úµã
Exit;
nodeList := ANode.ChildNodes;
for i := 0 to nodeList.Count - 1 do
begin
mNodeName := nodeList[i].NodeName; AStrList.add('~'+mNodeName);


if nodeList[i].IsTextElement then
begin
AStrList.Add('*'+nodeList[i].NodeName);
if nodeList[i].NodeName = 'Conn' then
begin
//code := nodeList[i].NodeValue;
AStrList.Add('*'+nodeList[i].NodeName);
end

else if nodeList[i].HasChildNodes then
begin
AStrList.Add('c,'+nodeList[i].NodeName);
if nodeList[i].NodeName='Conn' then begin
AStrList.Add('*'+nodeList[i].ChildNodes[0].nodevalue);
AStrList.Add('*'+nodeList[i].ChildNodes.Nodes['userid'].nodevalue);
AStrList.Add('');

end else
if nodeList[i].NodeName='module' then begin
// AStrList.Add('');
AStrList.Add('->'+nodeList[i].Attributes['id']);
AStrList.Add('->'+nodeList[i].ChildNodes.Nodes['sql'].Text ); AStrList.Add('');
//trList.Add('->'+nodeList[i].ChildValues['sql']);
end else
if nodeList[i].NodeName='test' then begin
// AStrList.Add('');
AStrList.Add('->'+nodeList[i].Attributes['id']);
AStrList.Add('->'+nodeList[i].ChildNodes.Nodes['sql'].NodeValue ); AStrList.Add('');
// XMLDocument1.DocumentElement.ChildNodes.Nodes['St'].NodeValue
end else
if nodeList[i].NodeName='jsf' then begin
// AStrList.Add('');
AStrList.Add('->'+nodeList[i].Attributes['id']);
AStrList.Add('->'+nodeList[i].Attributes['lx']);

AStrList.Add('->'+nodeList[i].ChildNodes[0].NodeValue );
// XMLDocument1.DocumentElement.Nodes['St'].NodeValue
AStrList.Add('');
end;
end;

posted on 2022-07-12 16:46  rightway  阅读(15)  评论(0)    收藏  举报

导航