0

I use mini-xml to create a xml file. My format is as follow.

<?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>

I like to write those data into xml file. I looked for samples, but not easy to find. I can create the following elements.

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");

But actual writing to xml file, no idea how to write to xml file. May I have a sample how to use mini-xml to create xml file in c/c++.

Thanks

batuman
  • 7,066
  • 26
  • 107
  • 229

1 Answers1

1

Looking at the documentation in the Saving XML paragraph it seems pretty obvious:

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

If you can, I suggest you to use another C++ xml library (such as pugyxml, tinyxml to name a few). Your library feels old, not very C++ish, and just maintained for bugs.

coincoin
  • 4,595
  • 3
  • 23
  • 47