var xmld; i,j; node,nodec, nodel; s; dbname,t,ttxt; procedure kasitteletuotetxt(tnode,tnro); var i,j; kentta,txtkentat,txtnode; ots; f; begin for i:= 0 to tnode.childnodes.length-1 do begin txtnode := tnode.childnodes.item(i); txtkentat := txtnode.childnodes; for j:= 0 to txtkentat.length -1 do begin kentta := txtkentat.item(j); if kentta.nodename='otsikko' then begin if kentta.childnodes.length > 0 then ots := kentta.childnodes.item(0).nodevalue else ots := ''; if ttxt.findkey2(tnro,ots) then ttxt.edit else begin ttxt.insert; ttxt.FieldByName('tuotenro').asstring := tnro; ttxt.FieldByName('otsikko').asstring := ots; end; end else begin if kentta.childnodes.length > 0 then // tarkastus ettei ole tyhjä esim begin f := ttxt.FieldByName(kentta.nodename); if f is tbooleanfield then f.asboolean := kentta.childnodes.item(0).nodevalue; else f.asstring := kentta.childnodes.item(0).nodevalue; end; end; end; if ttxt.state <> dsBrowse then begin ttxt.post; end; end; end; procedure kasitteletuotteet(tnode); var i,j; kentta,tuotekentat,tuotenode; nro; begin for i:= 0 to tnode.childnodes.length-1 do begin tuotenode := tnode.childnodes.item(i); tuotekentat := tuotenode.childnodes; for j:= 0 to tuotekentat.length -1 do begin kentta := tuotekentat.item(j); if kentta.nodename='tekstit' then kasitteletuotetxt(kentta,nro); else if kentta.nodename='numero' then begin nro := kentta.childnodes.item(0).nodevalue; if t.findkey1(nro) then t.edit else begin t.insert; t.FieldByName('numero').asstring := nro; end; end else begin if kentta.childnodes.length > 0 then // tarkastus ettei ole tyhjä esim t.FieldByName(kentta.nodename).asstring := kentta.childnodes.item(0).nodevalue; end; end; if t.state <> dsBrowse then t.post; end; end; begin dbname := 'kirkar'; t := ttbtable.Create(nil); t.databasename := dbname; t.tablename := 'tuote'; t.open; ttxt := ttbtable.Create(nil); ttxt.databasename := dbname; ttxt.tablename := 'tuotetxt'; ttxt.open; xmld := CreateOleObject('microsoft.xmldom'); xmld.validateonparse := false; if xmld.Load('koe.xml') then begin if xmld.documentElement.nodename = 'skjdata' then begin nodel := xmld.DocumentElement.ChildNodes; xmlD.getElementsByTagName('title'); for j:= 0 to nodel.length-1 do begin if nodel.item(j).nodename='tuotteet' then kasitteletuotteet(nodel.item(j)); end; end else ShowMessage('Ei skjdataa'); xmld := unassigned; end else begin s := xmld.ParseError; showmessage('load failed '+#13+ 'Error #: ' + IntToStr(s.errorCode) + ': ' + s.reason +#13+ 'Line #: '+ IntToStr(s.Line) + #13+ 'Line Position: ' + IntToStr(s.linepos) +#13+ 'Position In File: ' + IntToStr(s.filepos) +#13+ 'Source Text: ' + s.srcText +#13+ 'Document URL: ' + s.url ); end; t.close; t.free; ttxt.close; ttxt.free; end;