DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document; try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); } catch (Throwable e) { throw new ConfigError("Could not parse data dictionary file"); }  Element documentElement = document.getDocumentElement(); if (!documentElement.getNodeName().equals("fix")) { throw new ConfigError( "Could not parse data dictionary file, or no <fix> node found at root"); }  if (!documentElement.hasAttribute("major")) { throw new ConfigError("major attribute not found on <fix>"); }  if (!documentElement.hasAttribute("minor")) { throw new ConfigError("minor attribute not found on <fix>"); }  setVersion("FIX." + documentElement.getAttribute("major") + "." + documentElement.getAttribute("minor"));   NodeList componentsNode = documentElement.getElementsByTagName("components"); if (componentsNode.getLength() > 0) { NodeList componentNodes = componentsNode.item(0).getChildNodes(); for (int i = 0; i < componentNodes.getLength(); i++) { Node componentNode = componentNodes.item(i); if (componentNode.getNodeName().equals("component")) { String name = getAttribute(componentNode, "name"); if (name == null) { throw new ConfigError("<component> does not have a name attribute"); } components.put(name, componentNode); } } }   NodeList fieldsNode = documentElement.getElementsByTagName("fields"); if (fieldsNode.getLength() == 0) { throw new ConfigError("<fields> section not found in data dictionary"); }  NodeList fieldNodes = fieldsNode.item(0).getChildNodes(); if (fieldNodes.getLength() == 0) { throw new ConfigError("No fields defined"); }  for (int i = 0; i < fieldNodes.getLength(); i++) { Node fieldNode = fieldNodes.item(i); if (fieldNode.getNodeName().equals("field")) { String name = getAttribute(fieldNode, "name"); if (name == null) { throw new ConfigError("<field> does not have a name attribute"); }  String number = getAttribute(fieldNode, "number"); if (number == null) { throw new ConfigError("<field> " + name + " does not have a number attribute"); }  int num = Integer.parseInt(number);  String type = getAttribute(fieldNode, "type"); if (type == null) { throw new ConfigError("<field> " + name + " does not have a type attribute"); }  addField(num); addFieldType(num, FieldType.fromName(getVersion(), type)); addFieldName(num, name);  NodeList valueNodes = fieldNode.getChildNodes(); for (int j = 0; j < valueNodes.getLength(); j++) { Node valueNode = valueNodes.item(j); if (valueNode.getNodeName().equals("value")) { String enumeration = getAttribute(valueNode, "enum"); if (enumeration == null) { throw new ConfigError("<value> does not have enum attribute in field " + name); } addFieldValue(num, enumeration); String description = getAttribute(valueNode, "description"); if (description != null) { addValueName(num, enumeration, description); } } }  } }   NodeList headerNode = documentElement.getElementsByTagName("header"); if (headerNode.getLength() == 0) { throw new ConfigError("<header> section not found in data dictionary"); }  NodeList headerFieldNodes = headerNode.item(0).getChildNodes(); if (headerFieldNodes.getLength() == 0) { throw new ConfigError("No header fields defined"); }  for (int i = 0; i < headerFieldNodes.getLength(); i++) { Node headerFieldNode = headerFieldNodes.item(i);  if (headerFieldNode.getNodeName().equals("field")) { String name = getAttribute(headerFieldNode, "name"); if (name == null) { throw new ConfigError("<field> does not have a name attribute"); } String required = "false"; addHeaderField(lookupXMLFieldNumber(document, name), required.equals("true")); }  }  NodeList trailerNode = documentElement.getElementsByTagName("trailer"); if (trailerNode.getLength() == 0) { throw new ConfigError("<trailer> section not found in data dictionary"); }  NodeList trailerFieldNodes = trailerNode.item(0).getChildNodes(); for (int i = 0; i < trailerFieldNodes.getLength(); i++) { Node trailerFieldNode = trailerFieldNodes.item(i);  if (trailerFieldNode.getNodeName().equals("field")) { String name = getAttribute(trailerFieldNode, "name"); if (name == null) { throw new ConfigError("<field> does not have a name attribute"); } String required = "false"; addTrailerField(lookupXMLFieldNumber(document, name), required.equals("true")); }  }   NodeList messagesNode = documentElement.getElementsByTagName("messages"); if (messagesNode.getLength() == 0) { throw new ConfigError("<messages> section not found in data dictionary"); }  NodeList messageNodes = messagesNode.item(0).getChildNodes(); if (messageNodes.getLength() == 0) { throw new ConfigError("No messages defined"); }  for (int i = 0; i < messageNodes.getLength(); i++) { Node messageNode = messageNodes.item(i); if (messageNode.getNodeName().equals("message")) { String msgtype = getAttribute(messageNode, "msgtype"); if (msgtype == null) { throw new ConfigError("<message> does not have a msgtype attribute"); } addMsgType(msgtype);  String name = getAttribute(messageNode, "name"); if (name != null) { addValueName(MsgType.FIELD, msgtype, name); }  NodeList messageFieldNodes = messageNode.getChildNodes(); if (messageFieldNodes.getLength() == 0) { throw new ConfigError("<message> contains no fields"); }  for (int j = 0; j < messageFieldNodes.getLength(); j++) { Node messageFieldNode = messageFieldNodes.item(j);  if (messageFieldNode.getNodeName().equals("field") || messageFieldNode.getNodeName().equals("group")) { name = getAttribute(messageFieldNode, "name"); if (name == null) { throw new ConfigError("<field> does not have a name attribute"); }  int num = lookupXMLFieldNumber(document, name); addMsgField(msgtype, num);  String required = getAttribute(messageFieldNode, "required"); if (required.equalsIgnoreCase("Y")) { addRequiredField(msgtype, num); }  } else if (messageFieldNode.getNodeName().equals("component")) {  String required = getAttribute(messageFieldNode, "required"); addXMLComponentFields(document, messageFieldNode, msgtype, this, required .equalsIgnoreCase("Y")); } if (messageFieldNode.getNodeName().equals("group")) { String required = getAttribute(messageFieldNode, "required"); addXMLGroup(document, messageFieldNode, msgtype, this, required .equalsIgnoreCase("Y")); } } } } }
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document; try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); } catch (Throwable e) { throw new ConfigError("Could not parse data dictionary file", e); }  Element documentElement = document.getDocumentElement(); if (!documentElement.getNodeName().equals("fix")) { throw new ConfigError( "Could not parse data dictionary file, or no <fix> node found at root"); }  if (!documentElement.hasAttribute("major")) { throw new ConfigError("major attribute not found on <fix>"); }  if (!documentElement.hasAttribute("minor")) { throw new ConfigError("minor attribute not found on <fix>"); }  setVersion("FIX." + documentElement.getAttribute("major") + "." + documentElement.getAttribute("minor"));   NodeList componentsNode = documentElement .getElementsByTagName("components"); if (componentsNode.getLength() > 0) { NodeList componentNodes = componentsNode.item(0).getChildNodes(); for (int i = 0; i < componentNodes.getLength(); i++) { Node componentNode = componentNodes.item(i); if (componentNode.getNodeName().equals("component")) { String name = getAttribute(componentNode, "name"); if (name == null) { throw new ConfigError( "<component> does not have a name attribute"); } components.put(name, componentNode); } } }   NodeList fieldsNode = documentElement.getElementsByTagName("fields"); if (fieldsNode.getLength() == 0) { throw new ConfigError( "<fields> section not found in data dictionary"); }  NodeList fieldNodes = fieldsNode.item(0).getChildNodes(); if (fieldNodes.getLength() == 0) { throw new ConfigError("No fields defined"); }  for (int i = 0; i < fieldNodes.getLength(); i++) { Node fieldNode = fieldNodes.item(i); if (fieldNode.getNodeName().equals("field")) { String name = getAttribute(fieldNode, "name"); if (name == null) { throw new ConfigError( "<field> does not have a name attribute"); }  String number = getAttribute(fieldNode, "number"); if (number == null) { throw new ConfigError("<field> " + name + " does not have a number attribute"); }  int num = Integer.parseInt(number);  String type = getAttribute(fieldNode, "type"); if (type == null) { throw new ConfigError("<field> " + name + " does not have a type attribute"); }  addField(num); addFieldType(num, FieldType.fromName(getVersion(), type)); addFieldName(num, name);  NodeList valueNodes = fieldNode.getChildNodes(); for (int j = 0; j < valueNodes.getLength(); j++) { Node valueNode = valueNodes.item(j); if (valueNode.getNodeName().equals("value")) { String enumeration = getAttribute(valueNode, "enum"); if (enumeration == null) { throw new ConfigError( "<value> does not have enum attribute in field " + name); } addFieldValue(num, enumeration); String description = getAttribute(valueNode, "description"); if (description != null) { addValueName(num, enumeration, description); } } }  } }   NodeList headerNode = documentElement.getElementsByTagName("header"); if (headerNode.getLength() == 0) { throw new ConfigError( "<header> section not found in data dictionary"); }  NodeList headerFieldNodes = headerNode.item(0).getChildNodes(); if (headerFieldNodes.getLength() == 0) { throw new ConfigError("No header fields defined"); }  for (int i = 0; i < headerFieldNodes.getLength(); i++) { Node headerFieldNode = headerFieldNodes.item(i);  if (headerFieldNode.getNodeName().equals("field")) { String name = getAttribute(headerFieldNode, "name"); if (name == null) { throw new ConfigError( "<field> does not have a name attribute"); } String required = "false"; addHeaderField(lookupXMLFieldNumber(document, name), required .equals("true")); }  }  NodeList trailerNode = documentElement.getElementsByTagName("trailer"); if (trailerNode.getLength() == 0) { throw new ConfigError( "<trailer> section not found in data dictionary"); }  NodeList trailerFieldNodes = trailerNode.item(0).getChildNodes(); for (int i = 0; i < trailerFieldNodes.getLength(); i++) { Node trailerFieldNode = trailerFieldNodes.item(i);  if (trailerFieldNode.getNodeName().equals("field")) { String name = getAttribute(trailerFieldNode, "name"); if (name == null) { throw new ConfigError( "<field> does not have a name attribute"); } String required = "false"; addTrailerField(lookupXMLFieldNumber(document, name), required .equals("true")); }  }   NodeList messagesNode = documentElement .getElementsByTagName("messages"); if (messagesNode.getLength() == 0) { throw new ConfigError( "<messages> section not found in data dictionary"); }  NodeList messageNodes = messagesNode.item(0).getChildNodes(); if (messageNodes.getLength() == 0) { throw new ConfigError("No messages defined"); }  for (int i = 0; i < messageNodes.getLength(); i++) { Node messageNode = messageNodes.item(i); if (messageNode.getNodeName().equals("message")) { String msgtype = getAttribute(messageNode, "msgtype"); if (msgtype == null) { throw new ConfigError( "<message> does not have a msgtype attribute"); } addMsgType(msgtype);  String name = getAttribute(messageNode, "name"); if (name != null) { addValueName(MsgType.FIELD, msgtype, name); }  NodeList messageFieldNodes = messageNode.getChildNodes(); if (messageFieldNodes.getLength() == 0) { throw new ConfigError("<message> contains no fields"); }  for (int j = 0; j < messageFieldNodes.getLength(); j++) { Node messageFieldNode = messageFieldNodes.item(j);  if (messageFieldNode.getNodeName().equals("field") || messageFieldNode.getNodeName().equals("group")) { name = getAttribute(messageFieldNode, "name"); if (name == null) { throw new ConfigError( "<field> does not have a name attribute"); }  int num = lookupXMLFieldNumber(document, name); addMsgField(msgtype, num);  String required = getAttribute(messageFieldNode, "required", NO); if (required == null) { throw new ConfigError("<" + messageFieldNode.getNodeName() + "> does not have a 'required' attribute"); } if (required.equalsIgnoreCase("Y")) { addRequiredField(msgtype, num); }  } else if (messageFieldNode.getNodeName().equals( "component")) {  String required = getAttribute(messageFieldNode, "required"); if (required == null) { throw new ConfigError( "<component> does not have a 'required' attribute"); } addXMLComponentFields(document, messageFieldNode, msgtype, this, required.equalsIgnoreCase("Y")); } if (messageFieldNode.getNodeName().equals("group")) { String required = getAttribute(messageFieldNode, "required"); if (required == null) { throw new ConfigError( "<group> does not have a 'required' attribute"); } addXMLGroup(document, messageFieldNode, msgtype, this, required.equalsIgnoreCase("Y")); } } } } }
    private void load(InputStream inputStream) throws ConfigError {        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();        Document document;        try {            DocumentBuilder builder = factory.newDocumentBuilder();            document = builder.parse(inputStream);        } catch (Throwable e) {            throw new ConfigError("Could not parse data dictionary file");        }        Element documentElement = document.getDocumentElement();        if (!documentElement.getNodeName().equals("fix")) {            throw new ConfigError(                    "Could not parse data dictionary file, or no <fix> node found at root");        }        if (!documentElement.hasAttribute("major")) {            throw new ConfigError("major attribute not found on <fix>");        }        if (!documentElement.hasAttribute("minor")) {            throw new ConfigError("minor attribute not found on <fix>");        }        setVersion("FIX." + documentElement.getAttribute("major") + "."                + documentElement.getAttribute("minor"));        // Index Components        NodeList componentsNode = documentElement.getElementsByTagName("components");        if (componentsNode.getLength() > 0) {            NodeList componentNodes = componentsNode.item(0).getChildNodes();            for (int i = 0; i < componentNodes.getLength(); i++) {                Node componentNode = componentNodes.item(i);                if (componentNode.getNodeName().equals("component")) {                    String name = getAttribute(componentNode, "name");                    if (name == null) {                        throw new ConfigError("<component> does not have a name attribute");                    }                    components.put(name, componentNode);                }            }        }        // FIELDS        NodeList fieldsNode = documentElement.getElementsByTagName("fields");        if (fieldsNode.getLength() == 0) {            throw new ConfigError("<fields> section not found in data dictionary");        }        NodeList fieldNodes = fieldsNode.item(0).getChildNodes();        if (fieldNodes.getLength() == 0) {            throw new ConfigError("No fields defined");        }        for (int i = 0; i < fieldNodes.getLength(); i++) {            Node fieldNode = fieldNodes.item(i);            if (fieldNode.getNodeName().equals("field")) {                String name = getAttribute(fieldNode, "name");                if (name == null) {                    throw new ConfigError("<field> does not have a name attribute");                }                String number = getAttribute(fieldNode, "number");                if (number == null) {                    throw new ConfigError("<field> " + name + " does not have a number attribute");                }                int num = Integer.parseInt(number);                String type = getAttribute(fieldNode, "type");                if (type == null) {                    throw new ConfigError("<field> " + name + " does not have a type attribute");                }                addField(num);                addFieldType(num, FieldType.fromName(getVersion(), type));                addFieldName(num, name);                NodeList valueNodes = fieldNode.getChildNodes();                for (int j = 0; j < valueNodes.getLength(); j++) {                    Node valueNode = valueNodes.item(j);                    if (valueNode.getNodeName().equals("value")) {                        String enumeration = getAttribute(valueNode, "enum");                        if (enumeration == null) {                            throw new ConfigError("<value> does not have enum attribute in field "                                    + name);                        }                        addFieldValue(num, enumeration);                        String description = getAttribute(valueNode, "description");                        if (description != null) {                            addValueName(num, enumeration, description);                        }                    }                }            }        }        // HEADER        NodeList headerNode = documentElement.getElementsByTagName("header");        if (headerNode.getLength() == 0) {            throw new ConfigError("<header> section not found in data dictionary");        }        NodeList headerFieldNodes = headerNode.item(0).getChildNodes();        if (headerFieldNodes.getLength() == 0) {            throw new ConfigError("No header fields defined");        }        for (int i = 0; i < headerFieldNodes.getLength(); i++) {            Node headerFieldNode = headerFieldNodes.item(i);            if (headerFieldNode.getNodeName().equals("field")) {                String name = getAttribute(headerFieldNode, "name");                if (name == null) {                    throw new ConfigError("<field> does not have a name attribute");                }                String required = "false";                addHeaderField(lookupXMLFieldNumber(document, name), required.equals("true"));            }        }        NodeList trailerNode = documentElement.getElementsByTagName("trailer");        if (trailerNode.getLength() == 0) {            throw new ConfigError("<trailer> section not found in data dictionary");        }        NodeList trailerFieldNodes = trailerNode.item(0).getChildNodes();        for (int i = 0; i < trailerFieldNodes.getLength(); i++) {            Node trailerFieldNode = trailerFieldNodes.item(i);            if (trailerFieldNode.getNodeName().equals("field")) {                String name = getAttribute(trailerFieldNode, "name");                if (name == null) {                    throw new ConfigError("<field> does not have a name attribute");                }                String required = "false";                addTrailerField(lookupXMLFieldNumber(document, name), required.equals("true"));            }        }        // MSGTYPE        NodeList messagesNode = documentElement.getElementsByTagName("messages");        if (messagesNode.getLength() == 0) {            throw new ConfigError("<messages> section not found in data dictionary");        }        NodeList messageNodes = messagesNode.item(0).getChildNodes();        if (messageNodes.getLength() == 0) {            throw new ConfigError("No messages defined");        }        for (int i = 0; i < messageNodes.getLength(); i++) {            Node messageNode = messageNodes.item(i);            if (messageNode.getNodeName().equals("message")) {                String msgtype = getAttribute(messageNode, "msgtype");                if (msgtype == null) {                    throw new ConfigError("<message> does not have a msgtype attribute");                }                addMsgType(msgtype);                String name = getAttribute(messageNode, "name");                if (name != null) {                    addValueName(MsgType.FIELD, msgtype, name);                }                NodeList messageFieldNodes = messageNode.getChildNodes();                if (messageFieldNodes.getLength() == 0) {                    throw new ConfigError("<message> contains no fields");                }                for (int j = 0; j < messageFieldNodes.getLength(); j++) {                    Node messageFieldNode = messageFieldNodes.item(j);                    if (messageFieldNode.getNodeName().equals("field")                            || messageFieldNode.getNodeName().equals("group")) {                        name = getAttribute(messageFieldNode, "name");                        if (name == null) {                            throw new ConfigError("<field> does not have a name attribute");                        }                        int num = lookupXMLFieldNumber(document, name);                        addMsgField(msgtype, num);                        String required = getAttribute(messageFieldNode, "required");                        if (required.equalsIgnoreCase("Y")) {                            addRequiredField(msgtype, num);                        }                    } else if (messageFieldNode.getNodeName().equals("component")) {                        String required = getAttribute(messageFieldNode, "required");                        addXMLComponentFields(document, messageFieldNode, msgtype, this, required                                .equalsIgnoreCase("Y"));                    }                    if (messageFieldNode.getNodeName().equals("group")) {                        String required = getAttribute(messageFieldNode, "required");                        addXMLGroup(document, messageFieldNode, msgtype, this, required                                .equalsIgnoreCase("Y"));                    }                }            }        }    }