我使用 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 文件。
谢谢