【问题标题】:Creating a xml file using mini-xml library使用 mini-xml 库创建 xml 文件
【发布时间】:2016-08-26 08:58:43
【问题描述】:

我使用 mini-xml 创建一个 xml 文件。 我的格式如下。

<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml-stylesheet type='text/xsl' href='image_metadata_stylesheet.xsl'?>
<dataset>
<name>imglab dataset</name>
<comment>Created by imglab tool.</comment>
<images>
  <image file='train/10.png'>
    <box top='154' left='450' width='56' height='155'/>
  </image>
  <image file='train/1051.png'>
    <box top='132' left='484' width='40' height='116'/>
    <box top='97' left='452' width='40' height='105'/>
    <box top='147' left='398' width='50' height='133'/>
  </image>
</images>
</dataset>

我喜欢将这些数据写入 xml 文件。 我找了样品,但不容易找到。 我可以创建以下元素。

FILE *fp;
 mxml_node_t *tree;
 fp = fopen("filename.xml", "w");
 if(fp==NULL){
    cout << "Error in xml file!" << endl;   
    exit(1);             
 }
 mxml_node_t *xml;    /* <?xml ... ?> */
 mxml_node_t *dataset;   /* <data> */
 mxml_node_t *images;   /* <data> */
 mxml_node_t *box;   /* <node> */
 mxml_node_t *image;  /* <group> */
 xml = mxmlNewXML("1.0");
 dataset = mxmlNewElement(xml, "dataset");
 images = mxmlNewElement(dataset, "images");
 image = mxmlNewElement(images, "image");
 box = mxmlNewElement(image, "box");

但实际写入 xml 文件,不知道如何写入 xml 文件。 我可以有一个示例如何使用 mini-xml 在 c/c++ 中创建 xml 文件。

谢谢

【问题讨论】:

    标签: c++ xml xml-parsing mini-xml


    【解决方案1】:

    查看 保存 XML 段落中的 documentation 似乎很明显:

     FILE *fp;
     mxml_node_t *tree;
     fp = fopen("filename.xml", "w");
     mxmlSaveFile(tree, fp, MXML_NO_CALLBACK);
     fclose(fp);
    

    如果可以,我建议您使用另一个 C++ xml 库(例如 pugyxml、tinyxml 等等)。您的库感觉很旧,不是很 C++,而且只是针对错误进行维护。

    【讨论】:

    • 怎么写,没有写示例。
    • 您不阅读文档吗?检查文档中的创建 XML 文档
    猜你喜欢
    • 2018-07-29
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多