如何从这个XML中提取数据(200分)

  • 主题发起人 主题发起人 love_yb97
  • 开始时间 开始时间
L

love_yb97

Unregistered / Unconfirmed
GUEST, unregistred user!
一、XML大概格式如下,数据大概500个
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by EasyTrade Genius (http://www.etsoft.biz/) -->
<?xml-stylesheet type='text/xsl' href='/ebrmxsl/report/XGF_m3.xsl'?>
<EasyTrade>
<Parameter>
<danweichar>质 量 部</danweichar>
<begin
chartime>2008年04月01</begin
chartime>
<dykqxs>0</dykqxs>
<zyzqxs>0</zyzqxs>
<endchartime>2008年04月02</endchartime>
<gmrz/>
<_xsl_>report/XGF_m3.xsl </_xsl_>
<xsxs>0</xsxs>
<yqxs>0</yqxs>
<dyzqxs>0</dyzqxs>
<endtime>20080402</endtime>
</Parameter>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<qqq>18464</qqq>
<sLG_090>0</sLG_090>
<sumLG_090>18464</sumLG_090>
</Record>
</FieldMember>
</daydbList>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sRD_023>0</sRD_023>
<sRD_024>6729728</sRD_024>
<sRD_025>8904191</sRD_025>
<sRD_040>16336431</sRD_040>
<sRD_041>0</sRD_041>
<sumRD_023>53773539</sumRD_023>
</Record>
</FieldMember>
</daydbList>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumyq1>3669483</sumyq1>
<yq3>1493844</yq3>
<sumyq25>196976</sumyq25>
<sumyq26>5.37</sumyq26>
<sumyq27>0.00</sumyq27>
<sumyq28>94.63</sumyq28>
<sumyq28>94.63</sumyq28>
<sumyxyq>10507</sumyxyq>
<sumQYYQ>26870</sumQYYQ>
<sumpgw>10194</sumpgw>
</Record>
</FieldMember>
</daydbList>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumdq1>647793</sumdq1>
<sumdq2>125474</sumdq2>
<sumdq3>1035047</sumdq3>
<sumdq4>2034669</sumdq4>
<dq058>116361</dq058>
<dq059>13</dq059>
<dq010>43341</dq010>
<dq060>5945</dq060>
<dq114>4348</dq114>
<sumdqZG>170008</sumdqZG>
<sumdq10>8932</sumdq10>
<sumdq20>-512728</sumdq20>
<sumdqpc>2602619</sumdqpc>
<sumdqpcl>97.02</sumdqpcl>
<ndzxDQ>80326</ndzxDQ>
</Record>
</FieldMember>
</daydbList>
<gjmList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumGL_002G>527876</sumGL_002G>
<sumGL_002J>308906</sumGL_002J>
<sumGL_020G>710365</sumGL_020G>
<sumGL_020J>415635</sumGL_020J>
<sumXC_001G>0</sumXC_001G>
<sumXC_001J>0</sumXC_001J>
<sumQT_001J>56309</sumQT_001J>
<sumQT_040G>35132</sumQT_040G>
<sumQT_040J>28630</sumQT_040J>
<sumLZ_013G>3496</sumLZ_013G>
<sumLZ_013J>2834</sumLZ_013J>
</Record>
</FieldMember>
</gjmList>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
<Record>
<sumDL_001>11943957</sumDL_001>
<sumDL_002>11699077</sumDL_002>
<sumDL_003>11448806</sumDL_003>
<sumDL_004>13457038</sumDL_004>
<sumDL_005>22477</sumDL_005>
<sumDL_006>1006676</sumDL_006>
<sumQYGM>340392</sumQYGM>
<sumQYJM>52584</sumQYJM>
<sumWBJM>10</sumWBJM>
<jtjm>347892</jtjm>
<ndzxJM>3413637</ndzxJM>
</Record>
</FieldMember>
</daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumzq1>3510</sumzq1>
<sumzq2>376</sumzq2>
<sumzq3>67</sumzq3>
<sumzq4>0</sumzq4>
<zq5>1878</zq5>
<sumzq6>399</sumzq6>
<sumzq7>0</sumzq7>
<sumzq8>0</sumzq8>
</Record>
</FieldMember>
</daydbList>
<gjmList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumGL_002G>527876</sumGL_002G>
<sumGL_002J>308906</sumGL_002J>
<sumYS_008G>3270</sumYS_008G>
</Record>
</FieldMember>
</gjmList>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<LT_HS>1306794</LT_HS>
<sumGL_008>53874</sumGL_008>
<sumQT_016>0</sumQT_016>
<sumDL_064>185305</sumDL_064>
<sumQT_039>646</sumQT_039>
<HS>1733003</HS>
</Record>
</FieldMember>
</daydbList>
</EasyTrade>
二、问题
我需要提取EasyTrade.daydbList.FieldMember.Record节点下的所有属性和值,并放入数据库表中,但由于EasyTrade节点下有很多个daydbList节点,不知道如何提取这些数据,请大家帮忙一下,最好给出源码,初学勿笑,谢谢!!
 
利用 xml 的 xpath 直接检索定位
 
可以再详细点吗,或者写点源码吗 ,谢谢
 
由于楼主给出的 XML 文本有不对称的地方,我删除了不正确的地方用于测试。
<?xml version="1.0" encoding="GB2312"?>
<EasyTrade>
<Parameter>
<danweichar>质 量 部</danweichar>
<begin
chartime>2008年04月01</begin
chartime>
<dykqxs>0</dykqxs>
<zyzqxs>0</zyzqxs>
<endchartime>2008年04月02</endchartime>
<gmrz/>
<_xsl_>report/XGF_m3.xsl </_xsl_>
<xsxs>0</xsxs>
<yqxs>0</yqxs>
<dyzqxs>0</dyzqxs>
<endtime>20080402</endtime>
</Parameter>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<qqq>18464</qqq>
<sLG_090>0</sLG_090>
<sumLG_090>18464</sumLG_090>
</Record>
</FieldMember>
</daydbList>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sRD_023>0</sRD_023>
<sRD_024>6729728</sRD_024>
<sRD_025>8904191</sRD_025>
<sRD_040>16336431</sRD_040>
<sRD_041>0</sRD_041>
<sumRD_023>53773539</sumRD_023>
</Record>
</FieldMember>
</daydbList>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumyq1>3669483</sumyq1>
<yq3>1493844</yq3>
<sumyq25>196976</sumyq25>
<sumyq26>5.37</sumyq26>
<sumyq27>0.00</sumyq27>
<sumyq28>94.63</sumyq28>
<sumyq28>94.63</sumyq28>
<sumyxyq>10507</sumyxyq>
<sumQYYQ>26870</sumQYYQ>
<sumpgw>10194</sumpgw>
</Record>
</FieldMember>
</daydbList>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumdq1>647793</sumdq1>
<sumdq2>125474</sumdq2>
<sumdq3>1035047</sumdq3>
<sumdq4>2034669</sumdq4>
<dq058>116361</dq058>
<dq059>13</dq059>
<dq010>43341</dq010>
<dq060>5945</dq060>
<dq114>4348</dq114>
<sumdqZG>170008</sumdqZG>
<sumdq10>8932</sumdq10>
<sumdq20>-512728</sumdq20>
<sumdqpc>2602619</sumdqpc>
<sumdqpcl>97.02</sumdqpcl>
<ndzxDQ>80326</ndzxDQ>
</Record>
</FieldMember>
</daydbList>
<gjmList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<sumGL_002G>527876</sumGL_002G>
<sumGL_002J>308906</sumGL_002J>
<sumGL_020G>710365</sumGL_020G>
<sumGL_020J>415635</sumGL_020J>
<sumXC_001G>0</sumXC_001G>
<sumXC_001J>0</sumXC_001J>
<sumQT_001J>56309</sumQT_001J>
<sumQT_040G>35132</sumQT_040G>
<sumQT_040J>28630</sumQT_040J>
<sumLZ_013G>3496</sumLZ_013G>
<sumLZ_013J>2834</sumLZ_013J>
</Record>
</FieldMember>
</gjmList>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
<Record>
<sumDL_001>11943957</sumDL_001>
<sumDL_002>11699077</sumDL_002>
<sumDL_003>11448806</sumDL_003>
<sumDL_004>13457038</sumDL_004>
<sumDL_005>22477</sumDL_005>
<sumDL_006>1006676</sumDL_006>
<sumQYGM>340392</sumQYGM>
<sumQYJM>52584</sumQYJM>
<sumWBJM>10</sumWBJM>
<jtjm>347892</jtjm>
<ndzxJM>3413637</ndzxJM>
</Record>
<daydbList>
<DataMember>
<Success>true</Success>
<Error>
<Code>0</Code>
</Error>
<CountInfo>
<This>1</This>
<Total>1</Total>
<Page>-1</Page>
</CountInfo>
</DataMember>
<FieldMember>
<Record>
<LT_HS>1306794</LT_HS>
<sumGL_008>53874</sumGL_008>
<sumQT_016>0</sumQT_016>
<sumDL_064>185305</sumDL_064>
<sumQT_039>646</sumQT_039>
<HS a="123" b="456">1733003</HS>
</Record>
</FieldMember>
</daydbList>
</EasyTrade>
//代码如下
//使用 TXMLDocument 组件
procedure TForm1.Button1Click(Sender: TObject);
var
rNode,cNode,sNode: IXMLNode;
i,j,k: Integer;
begin
XMLDocument1.LoadFromFile('c:/1.xml');
XMLDocument1.Active := True;
rNode := XMLDocument1.Node;
rNode := rNode.ChildNodes.Nodes[1];
for i := 0 to rNode.ChildNodes.Count - 1do
begin
cNode := rNode.ChildNodes.Nodes;
if cNode.NodeName <> 'daydbList' then
Continue;
cNode := cNode.ChildNodes.FindNode('FieldMember');
if cNode = nil then
Continue;
cNode := cNode.ChildNodes.FindNode('Record');
if cNode = nil then
Continue;
for j := 0 to cNode.ChildNodes.Count - 1do
begin
sNode := cNode.ChildNodes.Nodes[j];
//读取数据
Memo1.Lines.Add('[' + sNode.NodeName + ']=' + sNode.NodeValue);
//读取属性
for k := 0 to sNode.AttributeNodes.Count - 1do
begin
Memo1.Lines.Add(sNode.AttributeNodes[k].NodeName + '=' +
sNode.AttributeNodes[k].NodeValue);
end;
end;
end;
end;
 
多人接受答案了。
 
后退
顶部