/// <summary> Copies data from a group object into the corresponding group element, creating any
        /// necessary child nodes.
        /// </summary>
        private void  encode(Genetibase.NuGenHL7.model.Group groupObject, System.Xml.XmlElement groupElement)
        {
            System.String[] childNames  = groupObject.Names;
            System.String   messageName = groupObject.Message.getName();

            try
            {
                for (int i = 0; i < childNames.Length; i++)
                {
                    Structure[] reps = groupObject.getAll(childNames[i]);
                    for (int j = 0; j < reps.Length; j++)
                    {
                        System.Xml.XmlElement childElement = groupElement.OwnerDocument.CreateElement(makeGroupElementName(messageName, childNames[i]));
                        groupElement.AppendChild(childElement);
                        if (reps[j] is Group)
                        {
                            encode((Group)reps[j], childElement);
                        }
                        else if (reps[j] is Segment)
                        {
                            encode((Segment)reps[j], childElement);
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                throw new NuGenHL7Exception("Can't encode group " + groupObject.GetType().FullName, NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e);
            }
        }
        /// <summary> Populates the given group object with data from the given group element, ignoring
        /// any unrecognized nodes.
        /// </summary>
        private void  parse(Genetibase.NuGenHL7.model.Group groupObject, System.Xml.XmlElement groupElement)
        {
            System.String[] childNames  = groupObject.Names;
            System.String   messageName = groupObject.Message.getName();

            System.Xml.XmlNodeList       allChildNodes       = groupElement.ChildNodes;
            System.Collections.ArrayList unparsedElementList = new System.Collections.ArrayList();
            for (int i = 0; i < allChildNodes.Count; i++)
            {
                System.Xml.XmlNode node = allChildNodes.Item(i);
                System.String      name = node.Name;
                if (System.Convert.ToInt16(node.NodeType) == (short)System.Xml.XmlNodeType.Element && !unparsedElementList.Contains(name))
                {
                    unparsedElementList.Add(name);
                }
            }

            //we're not too fussy about order here (all occurances get parsed as repetitions) ...
            for (int i = 0; i < childNames.Length; i++)
            {
                SupportClass.ICollectionSupport.Remove(unparsedElementList, childNames[i]);
                parseReps(groupElement, groupObject, messageName, childNames[i], childNames[i]);
            }

            for (int i = 0; i < unparsedElementList.Count; i++)
            {
                System.String segName      = (System.String)unparsedElementList[i];
                System.String segIndexName = groupObject.addNonstandardSegment(segName);
                parseReps(groupElement, groupObject, messageName, segName, segIndexName);
            }
        }