delphi解析xml

delphi解析xml

	 //解析xml (自己做的时候写的,仅供参考)

ComXML := LoadXMLData(jmxml);
XMLNode := ComXML.DocumentElement;
if not XMLNode.HasChildNodes then Exit;
nodeList := XMLNode.ChildNodes;

for i := 0 to nodeList.Count - 1 do
begin
if nodeList[i].IsTextElement then //元素
begin
if nodeList[i].NodeName=‘code’ then
begin
code :=nodeList[i].NodeValue;
end
else if nodeList[i].NodeName=‘msg’ then
begin
if msg = ‘’ then
begin
msg:=’’;
end
else
begin
msg:=nodeList[i].NodeValue;
end;
end
else if nodeList[i].NodeName=‘counts’ then
begin
counts:=nodeList[i].NodeValue;
end;
end
else if nodeList[i].HasChildNodes then //子节点
begin
nodeList1 := XMLNode.ChildNodes[‘lc01s’].ChildNodes;
for j:= 0 to nodeList1.Count - 1 do
begin
if nodeList1[j].HasChildNodes then
begin
nodeList2 := XMLNode.ChildNodes[‘lc01s’].ChildNodes[j].ChildNodes;

        for  z:= 0 to nodeList2.Count - 1 do
        begin
            if nodeList2[z].NodeName='aac001'  then
              begin
                aac001 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alca02' then
              begin
                 alca02 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aab001' then
              begin
                 aab001 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aab009' then
              begin
                 aab009 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aab301' then
              begin
                 aab301 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aac002' then
              begin
                 aac002 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aac003' then
              begin
                 aac003 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aac004' then
              begin
                 aac004 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aaea06' then
              begin
                 aaea06 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='akb020' then
              begin
                 akb020 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc020' then
              begin
                 alc020 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc021' then
              begin
                 alc021 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc022' then
              begin
                 alc022 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc024' then
              begin
                 alc024 :=vartostr( nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc023' then
              begin
                 alc023 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc027' then
              begin
                 alc027 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc060' then
              begin
                 alc060 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='ala040' then
              begin
                 ala040 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='alc084' then
              begin
                 alc084 := vartostr(nodeList2[z].NodeValue);
              end
           else if nodeList2[z].NodeName='aae116' then
              begin
                 aae116 := vartostr(nodeList2[z].NodeValue);
              end;
        end;
     end;

   end;
end;

end;

你可能感兴趣的:(delphi)