Example #1
0
        public void CanFindByMatchingAttributeNames_SkipsUnacceptable()
        {
            const string sourceXml =
            @"<?xml version='1.0' encoding='utf-8'?>
            <ldml>
            <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' />
            </ldml>";
            const string otherXml =
            @"<?xml version='1.0' encoding='utf-8'?>
            <ldml>
            <special xmlns:fw='urn://fieldworks.sil.org/ldmlExtensions/v1' />
            <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' />
            <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v2' />
            </ldml>";

            var sourceDoc = new XmlDocument();
            sourceDoc.LoadXml(sourceXml);
            var nodeToMatch = sourceDoc.DocumentElement.FirstChild;

            var otherDoc = new XmlDocument();
            otherDoc.LoadXml(otherXml);

            var nodeMatcher = new FindByMatchingAttributeNames(new HashSet<string> { "xmlns:palaso" });

            // We don't want the first xmlns:palaso child (someone else deleted it, maybe)
            var acceptableTargets =
                new HashSet<XmlNode>(new[] {otherDoc.DocumentElement.FirstChild, otherDoc.DocumentElement.ChildNodes[2]});
            Assert.AreSame(otherDoc.DocumentElement.ChildNodes[2],
                nodeMatcher.GetNodeToMerge(nodeToMatch, otherDoc.DocumentElement, acceptableTargets));
        }
Example #2
0
        public void CanFindByMatchingAttributeNames()
        {
            const string sourceXml =
            @"<?xml version='1.0' encoding='utf-8'?>
            <ldml>
            <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' />
            </ldml>";
            const string otherXml =
            @"<?xml version='1.0' encoding='utf-8'?>
            <ldml>
            <special xmlns:fw='urn://fieldworks.sil.org/ldmlExtensions/v1' />
            <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' />
            </ldml>";

            var sourceDoc = new XmlDocument();
            sourceDoc.LoadXml(sourceXml);
            var nodeToMatch = sourceDoc.DocumentElement.FirstChild;

            var otherDoc = new XmlDocument();
            otherDoc.LoadXml(otherXml);

            var nodeMatcher = new FindByMatchingAttributeNames(new HashSet<string> { "xmlns:palaso" });
            Assert.AreSame(otherDoc.DocumentElement.ChildNodes[1],
                nodeMatcher.GetNodeToMerge(nodeToMatch, otherDoc.DocumentElement, SetFromChildren.Get(otherDoc.DocumentElement)));
        }