예제 #1
0
        private void AttachingCore(DomObject instance)
        {
            if (!(instance is DomContainer))
            {
                return;
            }

            var doc = (instance is DomDocument dd) ? dd : instance.OwnerDocument;

            // Special case: monitor the document node to add it to the document element
            // if the document element is later added
            DomObserver docElement = null;

            if (instance is DomDocument document)
            {
                docElement = doc.ObserveChildNodes((DomNode)instance, AddNamespaceToDocumentElement, DomScope.Target);
                if (document.DocumentElement != null)
                {
                    document.DocumentElement.NameContext = new XmlNameContext();
                }
            }

            _observer = DomObserver.Compose(
                doc.ObserveAttributes((DomNode)instance, FixupNamespace, DomScope.TargetAndDescendants),
                docElement
                );
        }
            public ElementsByAttributeIndex(DomDocument owner, DomName name, Func <string, TKey> func, IEqualityComparer <TKey> comparer) : base(comparer)
            {
                _attributeName = name;
                _func          = func;
                _observer      = DomObserver.Compose(
                    owner.ObserveAttributes(name, Handler),
                    owner.ObserveChildNodes(Handler)
                    );

                foreach (var desc in owner.DescendantsAndSelf)
                {
                    Add(desc.Attribute(_attributeName), desc);
                }
            }