return 0;
}
+/**
+ * Return DOM fragment for current XML tag from file.
+ * \param file XML file being processed.
+ * \return Fragment representing DOM fragment for configuration element.
+ */
+static AddressIfFragment *addrindex_read_fragment( XMLFile *file ) {
+ AddressIfFragment *fragment;
+ AddressIfFragment *child;
+ AddressIfAttrib *nv;
+ XMLTag *xtag;
+ GList *list;
+ GList *attr;
+ gchar *name;
+ gchar *value;
+ guint prevLevel;
+ gint rc;
+
+ /* g_print( "addrindex_read_fragment\n" ); */
+
+ prevLevel = file->level;
+
+ /* Get current tag name */
+ xtag = xml_get_current_tag( file );
+
+ /* Create new fragment */
+ fragment = g_new0( AddressIfFragment, 1 );
+ fragment->name = g_strdup( xtag->tag );
+ fragment->children = NULL;
+ fragment->attributes = NULL;
+
+ /* Read attributes */
+ list = NULL;
+ attr = xml_get_current_tag_attr( file );
+ while( attr ) {
+ name = ((XMLAttr *)attr->data)->name;
+ value = ((XMLAttr *)attr->data)->value;
+ nv = g_new0( AddressIfAttrib, 1 );
+ nv->name = g_strdup( name );
+ nv->value = g_strdup( value );
+ list = g_list_append( list, nv );
+ attr = g_list_next( attr );
+ }
+ fragment->attributes = list;
+
+ /* Now read the children */
+ while( TRUE ) {
+ rc = xml_parse_next_tag( file );
+ if( rc != 0 ) {
+ /* End of file? */
+ break;
+ }
+ if( file->level < prevLevel ) {
+ /* We must be above level we start at */
+ break;
+ }
+ child = addrindex_read_fragment( file );
+ fragment->children = g_list_append( fragment->children, child );
+ }
+
+ return fragment;
+}
+
+/**
+ * Write DOM fragment to file.
+ * \param fp File to write.
+ * \param fragment DOM fragment for configuration element.
+ * \param lvl Indent level.
+ */
+static int addrindex_write_fragment(
+ FILE *fp, const AddressIfFragment *fragment, const gint lvl )
+{
+ GList *node;
+
+ if( fragment ) {
+ if (addrindex_write_elem_s( fp, lvl, fragment->name ) < 0)
+ return -1;
+ node = fragment->attributes;
+ while( node ) {
+ AddressIfAttrib *nv = node->data;
+ if (addrindex_write_attr( fp, nv->name, nv->value ) < 0)
+ return -1;
+ node = g_list_next( node );
+ }
+ if( fragment->children ) {
+ if (fputs(" >\n", fp) == EOF)
+ return -1;
+
+ /* Output children */
+ node = fragment->children;
+ while( node ) {
+ AddressIfFragment *child = node->data;
+ if (addrindex_write_fragment( fp, child, 1+lvl ) < 0)
+ return -1;
+ node = g_list_next( node );
+ }
+
+ /* Output closing tag */
+ if (addrindex_write_elem_e( fp, lvl, fragment->name ) < 0)
+ return -1;
+ }
+ else {
+ if (fputs(" />\n", fp) == EOF)
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
/**
* Read/parse address index file, creating a data source for a regular
* intrinsic XML addressbook.