code: protected void generateTagRules() throws ReadTagsIOException {
      try {
        PrintWriter writer = new PrintWriter("typecheck.xml", "UTF-8");
        for (int tagId : tagMap.keySet()) {
          Tag tag = tagMap.get(tagId);
          writer.println("  <rule context=\"tag[id=" + tag.getId() + "]\">");
          String typeRule = "";
          for (String tagType : tag.getType()) {
            if (typeRule.length() > 0)
              typeRule += " || ";
            typeRule += "{type=='" + tagType + "'}";
          }
          writer.println("   <assert test=\"" + typeRule + "\">Tag type does not match</assert>");
          writer.println("  </rule>");
        }
        writer.close();
  
        writer = new PrintWriter("cardinalitycheck.xml", "UTF-8");
        for (int tagId : tagMap.keySet()) {
          Tag tag = tagMap.get(tagId);
          if (tag.getCardinality().length() > 0 && !tag.getCardinality().equals("N")) {
            try {
              int card = Integer.parseInt(tag.getCardinality());
              writer.println("  <rule context=\"tag[id=" + tag.getId() + "]\">");
              String typeRule = "{cardinality==" + card + "}";
              writer.println("   <assert test=\"" + typeRule
                  + "\">Tag cardinality does not match</assert>");
              writer.println("  </rule>");
            } catch (Exception ex) {
              // TODO: Deal with formulas
              System.err.println("Formula in tag " + tag.getName() + ": " + tag.getCardinality());
            }
          }
        }
        writer.close();
      } catch (Exception ex) {
        throw new ReadTagsIOException();
      }
    }
docs: Generate tag rules.
  
  @throws ReadTagsIOException the read tags io exception