示例#1
0
            public Element ElementFromDatabaseTag(DbTag dbTag)
            {
                Element element = new Element()
                {
                    ElementId = dbTag.TagId,
                    InnerText = dbTag.InnerText,
                    Name      = dbTag.Name
                };

                var elementAttributesQuery =
                    from attribute in TagsAndAttributes.Attributes
                    where attribute.TagId == dbTag.TagId
                    select attribute;

                foreach (var dbAttribute in elementAttributesQuery)
                {
                    Attribute attribute = new Attribute()
                    {
                        AttributeId = dbAttribute.AttributeId,
                        Name        = dbAttribute.Name,
                        Value       = dbAttribute.Value
                    };
                    element.Attributes.Add(attribute);
                }

                var elementChildrenQuery =
                    from tag in TagsAndAttributes.Tags
                    where tag.ParentId == dbTag.TagId
                    select tag;

                foreach (var dbChildTag in elementChildrenQuery)
                {
                    var child = ElementFromDatabaseTag(dbChildTag);
                    element.Children.Add(child);
                }

                return(element);
            }
示例#2
0
        private static Element ElementFromXmlNode(XmlNode node)
        {
            Element e = new Element()
            {
                ElementId  = Guid.NewGuid(),
                Name       = node.Name,
                Children   = new List <Element>(),
                Attributes = new List <Attribute>()
            };

            if (node.Attributes != null)
            {
                foreach (XmlAttribute nodeAttribute in node.Attributes)
                {
                    var attribute = new Attribute()
                    {
                        AttributeId = Guid.NewGuid(),
                        Name        = nodeAttribute.Name,
                        Value       = nodeAttribute.Value
                    };
                    e.Attributes.Add(attribute);
                }
            }

            foreach (XmlNode childNode in node.ChildNodes)
            {
                // get inner text without all child nodes' inner text
                if (childNode is XmlText)
                {
                    e.InnerText = childNode.Value;
                    continue; // don't include text nodes in the Elements' structure
                }

                e.Children.Add(ElementFromXmlNode(childNode));
            }

            return(e);
        }