+static void wrbuf_write_tag(WRBUF b, const char *tag, int opening)
+{
+ int i, fixup = 0;
+
+ /* see if we must fix the tag.. The grs.marc filter produces
+ a data1 tree with not well-formed XML */
+ if (*tag >= '0' && *tag <= '9')
+ fixup = 1;
+ for (i = 0; tag[i]; i++)
+ if (strchr( " <>$,()[]", tag[i]))
+ fixup = 1;
+ if (fixup)
+ {
+ wrbuf_puts(b, "tag");
+ if (opening)
+ {
+ wrbuf_puts(b, " value=\"");
+ wrbuf_xmlputs(b, tag);
+ wrbuf_puts(b, "\"");
+ }
+ }
+ else
+ wrbuf_puts(b, tag);
+}
+