Esempio n. 1
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Parses an XML node and create the corresponding
        /// GBaseAttribute.</summary>
        ///////////////////////////////////////////////////////////////////////
        public static GBaseAttribute ParseGBaseAttribute(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            GBaseAttribute attribute = new GBaseAttribute();

            attribute.Name = FromXmlTagName(node.LocalName);
            String value = Utilities.GetAttributeValue("type", node);

            if (value != null)
            {
                attribute.Type = GBaseAttributeType.ForName(value);
            }
            value = Utilities.GetAttributeValue("access", node);
            attribute.IsPrivate = "private".Equals(value);

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element)
                {
                    bool parsed = false;
                    if (child.NamespaceURI == GBaseNameTable.NSGBaseMeta)
                    {
                        object localName = child.LocalName;
                        if (localName.Equals("adjusted_name"))
                        {
                            attribute.AdjustedName = child.InnerText;
                            parsed = true;
                        }
                        else if (localName.Equals("adjusted_value"))
                        {
                            attribute.AdjustedValue = child.InnerText;
                            parsed = true;
                        }
                    }
                    // Keep everything else as XML
                    if (!parsed)
                    {
                        attribute[child.LocalName] = child.InnerXml;
                    }
                }
            }

            // If there are sub-elements, set the Content to null unless
            // there is clearly something in there.
            string content = ExtractDirectTextChildren(node);

            if (!"".Equals(content.Trim(kXmlWhitespaces)))
            {
                attribute.Content = content;
            }
            return(attribute);
        }
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Parses XML code and generates an ItemTypeAttributes
        /// object.</summary>
        ///////////////////////////////////////////////////////////////////////
        public static ItemTypeAttributes Parse(XmlNode xml)
        {
            List <AttributeId> attributeIds = new List <AttributeId>();

            for (XmlNode child = xml.FirstChild; child != null; child = child.NextSibling)
            {
                if ("attribute" == child.LocalName &&
                    child.Attributes != null &&
                    child.Attributes["type"] != null)
                {
                    GBaseAttributeType type = GBaseAttributeType.ForName(child.Attributes["type"].Value);
                    attributeIds.Add(new AttributeId(child.Attributes["name"].Value, type));
                }
            }

            return(new ItemTypeAttributes(attributeIds));
        }
Esempio n. 3
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Parses a gm:attribute tag and create the corresponding
        /// AttributeHistogram object.</summary>
        ///////////////////////////////////////////////////////////////////////
        public static AttributeHistogram Parse(XmlNode node)
        {
            if (node.Attributes != null)
            {
                string             name  = null;
                int                count = 0;
                GBaseAttributeType type  = null;

                name = Utilities.GetAttributeValue("name", node);
                String value = Utilities.GetAttributeValue("type", node);
                if (value != null)
                {
                    type = GBaseAttributeType.ForName(value);
                }
                value = Utilities.GetAttributeValue("count", node);
                if (value != null)
                {
                    count = NumberFormat.ToInt(value);
                }

                if (name != null && type != null)
                {
                    //TODO determine if this is correct.
                    List <HistogramValue> values = new List <HistogramValue>();
                    for (XmlNode child = node.FirstChild;
                         child != null;
                         child = child.NextSibling)
                    {
                        if (child.LocalName == "value")
                        {
                            value = Utilities.GetAttributeValue("count", child);

                            if (value != null)
                            {
                                int valueCount = NumberFormat.ToInt(value);
                                values.Add(new HistogramValue(child.InnerText, valueCount));
                            }
                        }
                    }
                    return(new AttributeHistogram(name, type, count, values));
                }
            }
            return(null);
        }