bcb写xml

前端之家收集整理的这篇文章主要介绍了bcb写xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//激活bom.xml
pXMLDocument->LoadFromFile(WideString("Bom.xml"));
pXMLDocument->Active = true;

//删除所有子节点,以便重新插入
//通过DocumentElement得到根节点root_node
_di_IXMLNode root_node=pXMLDocument->DocumentElement;
//得到根节点的子节点
_di_IXMLNodeList nodes = root_node->ChildNodes;
//得到子节点的个数
int nContnode = nodes->Count;
for(int i = nContnode - 1; i >= 0; i--)
{
nodes->Delete(i);

}

for(int i = 0; i < devi.size(); i++)
{
const CDeviceInfo &device = devi[i];
_di_IXMLNode node=pXMLDocument->DocumentElement;
node=node->AddChild(WideString("Device"));

_di_IXMLNode subnode=node->AddChild(WideString("项目代号"));
subnode->SetText(WideString(device.sCOL1));
subnode=node->AddChild(WideString("物资编码"));
subnode->SetText(WideString(device.sCOL2));
subnode=node->AddChild(WideString("器材名称"));
subnode->SetText(WideString(device.sCOL3));
subnode=node->AddChild(WideString("规格"));
subnode->SetText(WideString(device.sCOL4));
subnode=node->AddChild(WideString("型号"));
subnode->SetText(WideString(device.sCOL5));

subnode=node->AddChild(WideString("元器件值"));
subnode->SetText(WideString(device.sCOL6));
subnode=node->AddChild(WideString("执行标准"));
subnode->SetText(WideString(device.sCOL7));
subnode=node->AddChild(WideString("厂家"));
subnode->SetText(WideString(device.sCOL8));
subnode=node->AddChild(WideString("备注"));
subnode->SetText(WideString(device.sCOL9));
subnode=node->AddChild(WideString("计量单位"));
subnode->SetText(WideString(device.sCOL10));
subnode=node->AddChild(WideString("质量等级"));
subnode->SetText(WideString(device.sCOL11));

subnode=node->AddChild(WideString("封装形式"));
subnode->SetText(WideString(device.sCOL12));
subnode=node->AddChild(WideString("字段13"));
subnode->SetText(WideString(device.sCOL13));
subnode=node->AddChild(WideString("字段14"));
subnode->SetText(WideString(device.sCOL14));
subnode=node->AddChild(WideString("字段15"));
subnode->SetText(WideString(device.sCOL15));
subnode=node->AddChild(WideString("字段16"));
subnode->SetText(WideString(device.sCOL16));
subnode=node->AddChild(WideString("字段17"));
subnode->SetText(WideString(device.sCOL17));
subnode=node->AddChild(WideString("字段18"));
subnode->SetText(WideString(device.sCOL18));

}


pXMLDocument->SaveToFile(WideString("Bom.xml"));

以上是增加节点的方法,也可以增加属性,如下:

for(int i = 0; i < devi.size(); i++)
{
const CDeviceInfo &device = devi[i];
_di_IXMLNode node=pXMLDocument->DocumentElement;
node=node->AddChild(WideString("Device"));

node->SetAttribute(WideString("项目代号"),(device.sCOL1));
node->SetAttribute(WideString("物资编码"),(device.sCOL2));
node->SetAttribute(WideString("器材名称"),(device.sCOL3));
node->SetAttribute(WideString("规格"),(device.sCOL4));
node->SetAttribute(WideString("型号"),(device.sCOL5));
node->SetAttribute(WideString("元器件值"),(device.sCOL6));
node->SetAttribute(WideString("执行标准"),(device.sCOL7));
node->SetAttribute(WideString("厂家"),(device.sCOL8));
node->SetAttribute(WideString("备注"),(device.sCOL9));
node->SetAttribute(WideString("计量单位"),(device.sCOL10));
node->SetAttribute(WideString("质量等级"),(device.sCOL11));
node->SetAttribute(WideString("封装形式"),(device.sCOL12));
node->SetAttribute(WideString("字段13"),(device.sCOL13));
node->SetAttribute(WideString("字段14"),(device.sCOL14));
node->SetAttribute(WideString("字段15"),(device.sCOL15));
node->SetAttribute(WideString("字段16"),(device.sCOL16));
node->SetAttribute(WideString("字段17"),(device.sCOL17));
node->SetAttribute(WideString("字段18"),(device.sCOL18));
}


pXMLDocument->SaveToFile(WideString("Bom.xml"));

原文链接:https://www.f2er.com/xml/299771.html

猜你在找的XML相关文章