xml 写入数据
发布时间:2020-12-15 22:53:27 所属栏目:百科 来源:网络整理
导读:procedureTMyTemplate.SaveToXmlFile(qry:TQuery);varstr:widestring;XML:IXMLDocument;pNode:IXMLNode;nodeList,attrList:IXMLNodeList;i:Integer;beginifnotAssigned(qry)ornotqry.Activeor(qry.RecordCount3)thenbeginSay('定位信息不存在或不足(最少应有
procedureTMyTemplate.SaveToXmlFile(qry:TQuery); var str:widestring; XML:IXMLDocument; pNode:IXMLNode; nodeList,attrList:IXMLNodeList; i:Integer; begin ifnotAssigned(qry)ornotqry.Activeor(qry.RecordCount<3)thenbegin Say('定位信息不存在或不足(最少应有3条记录).'); exit; end; XML:=TXMLDocument.Create(FXMLFile); XML.Active:=True; pNode:=xml.DocumentElement; ifnotpNode.HasChildNodesthenExit; attrList:=pNode.AttributeNodes;{根节点的属性列表} //FCompany:=attrList['company'].NodeValue; //FModelName:=attrList['modelname'].NodeValue; nodeList:=pNode.ChildNodes;{根节点下的子节点列表} qry.First; //AttributeNodes['count'].NodeValue:=2;第一条记录是图像有效范围矩形 attrList['x1'].NodeValue:=qry.FieldByName('x1').AsInteger; attrList['y1'].NodeValue:=qry.FieldByName('y1').AsInteger; attrList['x2'].NodeValue:=qry.FieldByName('x2').AsInteger; attrList['y2'].NodeValue:=qry.FieldByName('y2').AsInteger; try withnodeList['IdentifyAreas'].ChildNodes['Area1']dobegin qry.Next;//规定第2,3条记录是第一识别区 //AttributeNodes['eName'].NodeValue:=qry.FieldByName('FieldName').AsString; //AttributeNodes['viewx'].NodeValue:=qry.FieldByName('viewx').AsInteger; //AttributeNodes['viewy'].NodeValue:=qry.FieldByName('viewy').AsInteger; AttributeNodes['x1'].NodeValue:=qry.FieldByName('x1').AsInteger; AttributeNodes['y1'].NodeValue:=qry.FieldByName('y1').AsInteger; AttributeNodes['x2'].NodeValue:=qry.FieldByName('x2').AsInteger; AttributeNodes['y2'].NodeValue:=qry.FieldByName('y2').AsInteger; end; withnodeList['IdentifyAreas'].ChildNodes['Area2']dobegin qry.Next; AttributeNodes['x1'].NodeValue:=qry.FieldByName('x1').AsInteger; AttributeNodes['y1'].NodeValue:=qry.FieldByName('y1').AsInteger; AttributeNodes['x2'].NodeValue:=qry.FieldByName('x2').AsInteger; AttributeNodes['y2'].NodeValue:=qry.FieldByName('y2').AsInteger; end; //调整分块节点个数 FIdentifyAreasCount:=2; FBlockCount:=qry.RecordCount-3; nodeList['blocks'].AttributeNodes['count'].NodeValue:=FBlockCount; //nodeList['blocks'].ChildNodes.Clear; i:=0; whilenodeList['blocks'].ChildNodes.Count<FBlockCountdobegin i:=i+1; str:='b'+IntToStr(i); pNode:=nodeList['blocks']; pNode.AddChild(str); //nodeList['blocks'].AddChild(str,-1); 编译通不过用上面两行替代 end; whilenodeList['blocks'].ChildNodes.Count>FBlockCountdobegin i:=nodeList['blocks'].ChildNodes.Count-1; pNode:=nodeList['blocks']; pNode.ChildNodes.Delete(i); //nodeList['blocks'].ChildNodes.Delete(i); 编译通不过用上面两行替代 end; //blocks节点 qry.Next;//指向第一个区块 fori:=0toFBlockCount-1dobegin withnodeList['blocks'].ChildNodes[i]dobegin AttributeNodes['x1'].NodeValue:=qry.FieldByName('x1').AsInteger; AttributeNodes['y1'].NodeValue:=qry.FieldByName('y1').AsInteger; AttributeNodes['x2'].NodeValue:=qry.FieldByName('x2').AsInteger; AttributeNodes['y2'].NodeValue:=qry.FieldByName('y2').AsInteger; end; qry.Next; end; XML.SaveToFile(FXMLFile); Finally XML.Active:=false; end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |