コード例 #1
0
        //! \brief override method for finding objects' information from a specified xml structure
        public override String[] Find(XmlDocument xmlDocument, XmlNode xmlRootNode)
        {
            if ((null == xmlDocument) || (null == xmlRootNode))
            {
                return(null);
            }

            List <String> tResultList = new List <String>();

            try
            {
                //! get root node

                XmlNode TargetNode = null;
                //! find targets from root node
                if (xmlRootNode.Name != XMLRootName)
                {
                    TargetNode = xmlRootNode.SelectSingleNode(XMLRootName);
                }
                else
                {
                    TargetNode = xmlRootNode;
                }

                if (null == TargetNode)
                {
                    if (0 == xmlRootNode.ChildNodes.Count)
                    {
                        return(null);
                    }

                    //! search for targets in each childnode
                    foreach (XmlNode xmlChildren in xmlRootNode.ChildNodes)
                    {
                        String[] tResult = Find(xmlDocument, xmlChildren);
                        if (null != tResult)
                        {
                            return(tResult);
                        }
                    }

                    return(null);
                }

                //! get parameter group set with index number
                XmlNodeList xmlParameterGroupSetList = TargetNode.SelectNodes(XMLObjectName);
                if (null == xmlParameterGroupSetList)
                {
                    return(null);
                }
                if (0 == xmlParameterGroupSetList.Count)
                {
                    return(null);
                }

                foreach (XmlNode tNodeItem in xmlParameterGroupSetList)
                {
                    XmlAttributeCollection tAttributes = tNodeItem.Attributes;
                    if (null == tAttributes)
                    {
                        continue;
                    }
                    if (0 == tAttributes.Count)
                    {
                        continue;
                    }

                    StringBuilder sbAttrib = new StringBuilder();
                    //! get all attribute string
                    foreach (XmlAttribute tAttribute in tAttributes)
                    {
                        if (null == tAttribute.Value)
                        {
                            continue;
                        }
                        else if ("" == tAttribute.Value.Trim())
                        {
                            continue;
                        }

                        sbAttrib.Append(tAttribute.Value);
                        sbAttrib.Append('\t');
                    }

                    tResultList.Add(sbAttrib.ToString());
                }
            }
            catch (Exception e)
            {
                m_Exception = e;
                return(null);
            }

            if (tResultList.Count > 0)
            {
                return(tResultList.ToArray());
            }

            return(null);
        }