const char* const XmlTag = "<?xml version=\"1.0\"?>\r\n"; CMarkup tempXml; tempXml.AddElem("Item"); tempXml.AddChildElem("ItemId",111); tempXml.AddChildElem("ItemName","My111"); CMarkup xmlDoc(XmlTag); xmlDoc.AddElem("Response"); xmlDoc.AddChildElem("CmdType","Catalog"); xmlDoc.AddChildElem("DeviceList"); xmlDoc.SetChildAttrib("Num",2); xmlDoc.IntoElem(); xmlDoc.AddChildElem("Item"); xmlDoc.IntoElem(); xmlDoc.AddChildElem("ItemId",1); xmlDoc.AddChildElem("ItemName","Name"); xmlDoc.OutOfElem(); xmlDoc.AddChildElem("Item"); xmlDoc.IntoElem(); xmlDoc.AddChildElem("ItemId",2); xmlDoc.AddChildElem("ItemName","Name2"); xmlDoc.OutOfElem(); xmlDoc.AddChildSubDoc(tempXml.GetDoc()); xmlDoc.OutOfElem();
产生的xml数据格式如下
<?xml version="1.0"?> <Response> <CmdType>Catalog</CmdType> <DeviceList Num="2"> <Item> <ItemId>1</ItemId> <ItemName>Name</ItemName> </Item> <Item> <ItemId>2</ItemId> <ItemName>Name2</ItemName> </Item> <Item> <ItemId>111</ItemId> <ItemName>My111</ItemName> </Item> </DeviceList> </Response>原文链接:https://www.f2er.com/xml/300092.html