コード例 #1
0
        public void MultipleAttributeKeyedElement_IsFound()
        {
            const string sourceXml = @"<root>
<CustomField name='Certified' class='WfiWordform' type='Boolean' />
</root>";
            const string otherXml  = @"<root>
<CustomField name='IsComplete' class='WfiWordform' type='Boolean' />
<CustomField name='Certified' class='WfiWordform' type='Boolean' />
<CustomField name='Checkpoint' class='WfiWordform' type='String' />
</root>";

            var sourceDoc = new XmlDocument();

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

            var otherDoc = new XmlDocument();

            otherDoc.LoadXml(otherXml);

            var nodeMatcher = new FindByMultipleKeyAttributes(new List <string> {
                "name", "class"
            });
            var result = nodeMatcher.GetNodeToMerge(nodeToMatch, otherDoc.DocumentElement, SetFromChildren.Get(otherDoc.DocumentElement));

            Assert.AreSame(otherDoc.DocumentElement.ChildNodes[1], result);
        }
コード例 #2
0
        public void MultipleAttributeKeyedElement_WithDoubleAndSingleQuoteInAttribute_IsFound()
        {
            const string sourceXml = @"<root>
<CustomField name='First quoted &quot;Apostrophe&apos;s&quot;' class='Second quoted &quot;Apostrophe&apos;s&quot;' type='Boolean' />
</root>";
            const string otherXml  = @"<root>
<CustomField name='IsComplete' class='WfiWordform' type='Boolean' />
<CustomField name='First quoted &quot;Apostrophe&apos;s&quot;' class='Second quoted &quot;Apostrophe&apos;s&quot;' type='Boolean' />
<CustomField name='Checkpoint' class='WfiWordform' type='String' />
</root>";

            var sourceDoc = new XmlDocument();

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

            var otherDoc = new XmlDocument();

            otherDoc.LoadXml(otherXml);

            var nodeMatcher = new FindByMultipleKeyAttributes(new List <string> {
                "name", "class"
            });

            if (Platform.IsMono || otherDoc.DocumentElement == null)
            {
                return;
            }

            var acceptableTargets = new HashSet <XmlNode>();

            foreach (XmlNode node in otherDoc.DocumentElement.ChildNodes)
            {
                acceptableTargets.Add(node);
            }
            var result = nodeMatcher.GetNodeToMerge(nodeToMatch, otherDoc.DocumentElement, acceptableTargets);

            Assert.AreSame(otherDoc.DocumentElement.ChildNodes[1], result);
        }