Example #1
0
        public WomElement(WomElement other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            this._name = other._name;

            WomPropertyCollection attrs = other._properties;
            if (attrs != null)
            {
                this._properties = new WomPropertyCollection(attrs);
            }

            if (other._content is string)
            {
                this._content = other._content;
            }
            else
            {
                WomElementCollection otherElementList = other._content as WomElementCollection;
                if (otherElementList != null)
                {
                    WomElementCollection elementList = ElementList;
                    for (int i = 0; i < otherElementList.Count; i++)
                    {
                        elementList.Add(new WomElement(otherElementList[i]));
                    }
                }
            }
        }
Example #2
0
        public WomElement(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.NodeType != XmlNodeType.Element)
            {
                throw new InvalidOperationException();
            }
            bool sameNameTable = (reader.NameTable == WomNameTable.Instance);
            if (sameNameTable)
            {
                this._name = reader.LocalName;
            }
            else
            {
                this._name = WomNameTable.Instance.Add(reader.LocalName);
            }

            if (reader.HasAttributes)
            {
                this._properties = new WomPropertyCollection(reader.AttributeCount);
                for (int i = 0; i < reader.AttributeCount; i++)
                {
                    reader.MoveToAttribute(i);
                    this._properties.Add(new WomProperty(reader.LocalName, reader.Value));
                }
                reader.MoveToElement();
            }

            if (!reader.IsEmptyElement)
            {
                reader.Read();
                ReadElementContentFrom(reader);
                if (reader.NodeType != XmlNodeType.EndElement)
                {
                    throw new InvalidOperationException();
                }
                if (_content == null)
                {
                    _content = String.Empty;
                }
            }
        }