Example: Custom Tags

gedcom4j supports custom tags. It should be noted, however, that due to the nature of custom tags and the fact that any program or user can just make one up any time they like, there is little that can be done with them from a parsing viewpoint other than to read them, make sure they are accessible to the user, and to write them.

So gedcom4j does just that...each class in the data model has a getCustomFacts() property accessor that contains the data parsed in these custom tags, along with some very common sub-structures, such as Notes, Source Citations, Date, Place, Type, etc.

By default, gedcom4j enforces the GEDCOM standard requirement that custom tags begin with an underscore (e.g., _FOOT, representing a footnote, in files exported from Family Tree Maker). Any other unrecognized tag that does not begin with an underscore is reported in the getErrors() collection of the GedcomParser and then ignored. This behavior can be changed by setting GedcomParser.setStrictCustomTags(false) prior to loading a file. When this property is false, unrecognized tags will be treated as custom tags even if they don't begin with underscores, and no errors will be issued. Beginning with v4.0.0 of gedcom4j, you can also direct that the parser completely ignore custom tags by setting GedcomParser.setIgnoreCustomTags(true).

The following example shows how a user might use gedcom4j to process custom tags. Family Tree Maker defines a custom tag _MDCL for medical information, and it is used as a child to INDI (individual) records in the GEDCOM. The example code, knowing about this tag and where to find it, loads a GEDCOM, scans through the individuals, and anyone who has a _MDCL custom tag on them gets printed to System.out along with the value of that tag.

package com.mattharrah.genealogy;
import java.io.IOException;
import org.gedcom4j.exception.GedcomParserException;
import org.gedcom4j.model.CustomFact;
import org.gedcom4j.model.Gedcom;
import org.gedcom4j.model.Individual;
import org.gedcom4j.parser.GedcomParser;
public class CustomTags {
    public static void main(String[] args) throws IOException, GedcomParserException {
        GedcomParser gp = new GedcomParser();
        gp.load("/Users/frizbog/Documents/Genealogy Misc/Harrah.ged");
        Gedcom g = gp.getGedcom();
        for (Individual i : g.getIndividuals().values()) {
            for (CustomFact cf : i.getCustomFacts()) {
                if ("_MDCL".equals(cf.getTag())) {
                    System.out.println(i + ": " + cf.getDescription());

This produces output similar to this:

William Columbia /Willis/ Sr., b.01 MAY 1878: Grey eyes, Brown hair, Ruddy complexion
William T. /Harrah/, spouse of Thedocia E. /Fox/, child of Mary A /Fox/ and George Washington /Harrah/, b.24 JUN 1872: Back broken on January 16, 1901
Harold Wilbur /Bailey/, spouse of Ida Matilda /Thompson/ aka Ida M /Thompson/, b.29 OCT 1898: Brown Hair, Brown Eyes in 1918.
William Cleveland /Barney/, spouse of Nancy E /Doles/, b.22 JAN 1885 / JAN 1885 / 29 NOV 1963: Right hand missing first three fingers
William Edward /Johnson/, child of Mary Edna /Gahm/ and William Moody /Johnson/, b.1921 / 1921: Died in infancy
Mary Evaline /Johnson/, child of Martha /Horton/ and William James /Johnson/: Died in infancy