J
jcs
Unregistered / Unconfirmed
GUEST, unregistred user!
{计时器2搜索到达预确报}<br>procedure TForm1.Timer2Timer(Sender: TObject);<br>var<br> searchResult : TSearchRec;<br><br>begin<br> if FindFirst('D:/DDYQB/*.xml', faAnyFile, searchResult) = 0 then<br> begin<br> XMLFileName:='D:/DDYQB/'+SearchResult.Name;<br> ChangXMLS(XMLFileName);<br> FetchXMLData;<br> InsertToDB;<br> deletefile('D:/DDYQB/'+searchResult.Name);<br> FindClose(searchResult);<br> end;<br>end;<br><br><br>{把XML文件中的第一行替换}<br>procedure TForm1.ChangXMLS(FileNameS: String);<br>var<br> F1, F2: TextFile;<br> Ch: Char;<br> str,str1,strgs,str2:String;<br> i:integer;<br>begin<br> str:='<?xml version="1.0" encoding="gb2312" ?>';<br> AssignFile(F1,FileNameS); //关联XML文件<br> Reset(F1); //将指针置于XML文件第一行<br> readln(F1,STR2);//读取XML文件中的第一行,但不写入临时文件中<br> AssignFile(F2,'temp.xml');<br> Rewrite(F2); //重新写临时XML文件<br> Write(F2,str); //向临时文件中写入信息<br><br> while not Eof(F1) do<br> begin<br> Read(F1, ch);<br> if ch='<' then<br> begin<br> ch:=' ';<br> Write(F2,ch);<br> ch:='<';<br> Write(F2,ch);<br> end else<br> Write(F2,ch);<br> end;<br> CloseFile(F2);<br> CloseFile(F1);<br> DeleteFile(FileNameS);<br> RenameFile('temp.xml',FileNameS); <br>end;<br><br>{从结构体中取出数据放在到StringGrid中}<br>procedure TForm1.FetchXMLData;<br>begin<br> XMLDocument1.FileName:=XMLFileName;<br> XMLDocument1.Active:=true;<br><br> FetchXMLDataToDataStruct;<br> StringGrid2.RowCount:=List1.Count+1;<br> for i := 0 to List1.Count-1 do //循环取各个Index信息<br> begin<br> XMLData1 := List1.Items; //顺序取一个Index信息<br> if (XMLData1<> nil) then<br> begin<br> stringgrid2.Cells[0,i+1]:=XMLData1.hFBRQ;<br> stringgrid2.Cells[1,i+1]:=XMLData1.hFBSF;<br> stringgrid2.Cells[2,i+1]:=XMLData1.hBZCC;<br><br> stringgrid2.Cells[3,i+1]:=StationName(XMLData1.hJYZ);<br> stringgrid2.Cells[4,i+1]:=XMLData1.hLCLS;<br> stringgrid2.Cells[5,i+1]:=XMLData1.hLCZiZ;<br> stringgrid2.Cells[6,i+1]:=XMLData1.hLCZaiZ1;<br> stringgrid2.Cells[7,i+1]:=XMLData1.hLCZongZ;<br> stringgrid2.Cells[8,i+1]:=XMLData1.hLCHC;<br> stringgrid2.Cells[9,i+1]:=XMLData1.hPBHJ;<br> stringgrid2.Cells[10,i+1]:=StationName(XMLData1.hFBZ);<br> end;<br> end;<br><br> StringGrid1.RowCount:=List.Count+1;<br> for i := 0 to List.Count-1 do //循环取各个Index信息<br> begin<br> XMLData := List.Items; //顺序取一个Index信息<br> if (XMLData<> nil) then<br> begin<br> stringgrid1.Cells[1,i+1]:=XMLData.tSXH;<br> stringgrid1.Cells[2,i+1]:=XMLData.tCZ;<br> stringgrid1.Cells[3,i+1]:=XMLData.tCH;<br> stringgrid1.Cells[4,i+1]:=XMLData.tZiZ;<br> stringgrid1.Cells[5,i+1]:=XMLData.tHC;<br> stringgrid1.Cells[6,i+1]:=XMLData.tKZBZ;<br> stringgrid1.Cells[7,i+1]:=XMLData.tZLBZ;<br> stringgrid1.Cells[8,i+1]:=XMLData.tJYBZ;<br> stringgrid1.Cells[9,i+1]:=XMLData.tHSBZ;<br> stringgrid1.Cells[10,i+1]:=XMLData.tBQBZ;<br> stringgrid1.Cells[11,i+1]:=XMLData.tQTBZ;<br> stringgrid1.Cells[12,i+1]:=XMLData.tZaiZ;<br> stringgrid1.Cells[13,i+1]:=StationName(XMLData.tDZ1);<br> stringgrid1.Cells[14,i+1]:=StationName(XMLData.tDZ2);<br> stringgrid1.Cells[15,i+1]:=XMLData.tPM;<br> stringgrid1.Cells[16,i+1]:=StationName(XMLData.tFZ);<br> stringgrid1.Cells[17,i+1]:=XMLData.tPB;<br> stringgrid1.Cells[18,i+1]:=XMLData.tJSL;<br> end;<br> end;<br>end;<br><br>{从XML文件中取出数据到结构体}<br>procedure TForm1.FetchXMLDataToDataStruct;<br>begin<br> try<br> List := TList.Create; //初始化列表<br> list1:=TList.Create;<br> Root := XMLDocument1.DocumentElement; //取XML文件的根结点,<br> Parent_Node := Root.ChildNodes.First; //使Parent_Node指向Index结点<br> while (Parent_Node <> nil) do //循环取多个index<br> begin<br> if (Parent_Node.NodeName ='head') then //判断是否为index结点<br> begin<br> XMLData1:=TXMLData1.Create;<br> Child_Node:=Parent_Node.ChildNodes.First;//使Child_Node指向该index的第一个子结点信息<br> while (Child_Node <> nil) do //循环取index的各个子各点<br> begin<br> if (Child_Node.NodeName = 'hFBRQ') then //判断是否为timeZone结点<br> XMLData1.hFBRQ := Child_Node.Text //取timeZone结点的值,取于timeZone字段中<br> else if (Child_Node.NodeName = 'hFBSF') then<br> XMLData1.hFBSF := Child_Node.Text<br> else if (Child_Node.NodeName = 'hBZCC') then<br> XMLData1.hBZCC:=Child_Node.Text<br> else if (Child_Node.NodeName = 'hJYZ') then<br> XMLData1.hJYZ := Child_Node.Text<br> else if (Child_Node.NodeName = 'hLCLS') then<br> XMLData1.hLCLS:=Child_Node.Text<br> else if (Child_Node.NodeName = 'hLCZiZ') then<br> XMLData1.hLCZiZ := Child_Node.Text<br> else if (Child_Node.NodeName = 'hLCZaiZ1') then<br> XMLData1.hLCZaiZ1:=Child_Node.Text<br> else if (Child_Node.NodeName = 'hLCZongZ') then<br> XMLData1.hLCZongZ:=Child_Node.Text<br> else if (Child_Node.NodeName = 'hLCHC') then<br> XMLData1.hLCHC := Child_Node.Text<br> else if (Child_Node.NodeName = 'hPBHJ') then<br> XMLData1.hPBHJ:=Child_Node.Text<br> else if (Child_Node.NodeName = 'hFBZ') then<br> XMLData1.hFBZ:=Child_Node.Text;<br><br> Child_Node := Child_Node.NextSibling; //顺序取下一个数据的子结点信息<br> end;<br> List1.Add(XMLData1); //把一个数据信息加入列表<br> end;<br><br><br><br> if (Parent_Node.NodeName ='text') then //判断是否为index结点<br> begin<br> Child_Node:=Parent_Node.ChildNodes.First;//使Child_Node指向该index的第一个子结点信息<br> while (Child_Node <> nil) do //循环取index的各个子各点<br> begin<br> if (Child_Node.NodeName='item') then<br> begin<br> XMLData:=TXMLData.Create;<br> SecondChild_node:=Child_node.ChildNodes.First;<br> while(SecondChild_node<>nil) do<br> begin<br> if (SecondChild_node.NodeName = 'tSXH') then //判断是否为timeZone结点<br> XMLData.tSXH := SecondChild_node.Text //取timeZone结点的值,取于timeZone字段中<br> else if (SecondChild_node.NodeName = 'tCZ') then<br> XMLData.tCZ := SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tCH') then<br> XMLData.tCH:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tZiZ') then<br> XMLData.tZiZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tHC') then<br> XMLData.tHC:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tKZBZ') then<br> XMLData.tKZBZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tZLBZ') then<br> XMLData.tZLBZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tJYBZ') then<br> XMLData.tJYBZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tHSBZ') then<br> XMLData.tHSBZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tBQBZ') then<br> XMLData.tBQBZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tQTBZ') then<br> XMLData.tQTBZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tZaiZ') then<br> XMLData.tZaiZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tDZ1') then<br> XMLData.tDZ1:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tDZ2') then<br> XMLData.tDZ2:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tPM') then<br> XMLData.tPM:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tFZ') then<br> XMLData.tFZ:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tPB') then<br> XMLData.tPB:=SecondChild_node.Text<br> else if (SecondChild_node.NodeName = 'tJSL') then<br> XMLData.tJSL:=SecondChild_node.Text;<br> SecondChild_node := SecondChild_node.NextSibling;<br> end;<br> List.Add(XMLData);<br> end;<br> Child_Node := Child_Node.NextSibling; //顺序取下一个数据的子结点信息<br> end;<br> //把一个数据信息加入列表<br> end;<br> Parent_Node := Parent_Node.NextSibling; //顺序取下一个数据信息<br> end;<br> finally<br> List.Free;<br> List1.Free;<br> end;<br>end;<br><br><br><br>定义了两个结构<br>type<br><br> TXMLData1 = class<br> hFBRQ : string;<br> hFBSF: string;<br> hBZCC: string;<br><br> hJYZ : string;<br> hLCLS: String;<br> hLCZiZ:string;<br> hLCZaiZ1:string;<br> hLCZongZ:string;<br> hLCHC: string;<br> hPBHJ: string;<br> hFBZ : string;<br> END;<br> {自定义结构}<br> TXMLData = class<br> tSXH : string;<br> tCZ : string;<br> tCH : string;<br> tZiZ : string;<br> tHC : string;<br> tKZBZ: string;<br> tZLBZ: string;<br> tJYBZ: string;<br> tHSBZ: string;<br> tBQBZ: string;<br> tQTBZ: string;<br> tZaiZ: string;<br> tDZ1 : string;<br> tDZ2 : string;<br> tPM : string;<br> tFZ : string;<br> tPB : string;<br> tJSL : string;<br> end;