当前位置: 首页>>代码示例>>C++>>正文


C++ XmlWriter::addAttribute方法代码示例

本文整理汇总了C++中XmlWriter::addAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlWriter::addAttribute方法的具体用法?C++ XmlWriter::addAttribute怎么用?C++ XmlWriter::addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlWriter的用法示例。


在下文中一共展示了XmlWriter::addAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

void main()
{
  //mOut("Testing XmlWriter");
  //mOut("=================");

  //mOut("creating XML writer object:"); 
  XmlWriter wtr;

  //mOut("adding XML declaration:");
  wtr.addDeclaration();
  //mOut(wtr.xml());

  //mOut("adding comment:");
  wtr.addComment("top level comment");
  //mOut(wtr.xml());

  //mOut("adding root element:");
  wtr.start("root");
  //mOut(wtr.xml());

  //mOut("adding attributes:");
  wtr.addAttribute("att1","val1");
  wtr.addAttribute("att2","val2");
  //mOut(wtr.xml());

  //mOut("adding comment:");
  wtr.addComment("comment in root's body");
  //mOut(wtr.xml());

  //mOut("Creating self-closing element:");
  XmlWriter sub1;
  sub1.start("child1 /");
 // mOut(sub1.xml());

  //mOut("adding attribute:");
  sub1.addAttribute("c1name","c1value");
  
  XmlWriter subsub1;
  subsub1.start("grand");
  subsub1.addBody("test grandchild");
  subsub1.end();
  sub1.addBody(subsub1.xml());


  //mOut(sub1.xml());
  
  //mOut("adding child to root's body:");
  wtr.addBody(sub1.xml());
  //mOut(wtr.xml());

  //mOut("adding another comment");
  wtr.addComment("another root's body comment");
  //mOut(wtr.xml());

  //mOut("adding string to root's body:"); 
  wtr.addBody("root's body");
  //mOut(wtr.xml());

  //mOut("closing root element:\n");
  wtr.end();
  mOut(wtr.xml());

  mOut("\n  writing XML to file \"Test.xml\":");
  std::ofstream out("test.xml");
  if(out.good())
  {
    out << wtr.xml().c_str();
    out.close();
  }
  std::cout << std::endl;

 /* mOut("creating composite element:");
  XmlWriter cwtr, bcwtr1, bcwtr2;
  std::string temp = 
    bcwtr1.element("child1","child1's body")
    .element("child2","child2's body").xml();
  std::cout << "\n  " << bcwtr1.xml();
  bcwtr1.clear();

  std::cout << "\n  " <<
    cwtr.start("parent")
    .addBody(bcwtr1.element("child1","child1's body").xml())
    .addBody(bcwtr2.element("child2","body2").xml())
    .end().xml();
  std::cout << "\n\n";*/
}
开发者ID:newton449,项目名称:virtual-server,代码行数:86,代码来源:XmlWriter.cpp


注:本文中的XmlWriter::addAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。