Пример #1
0
        public void TestVisitEntityRefTextNodes()
        {
            string before   = @"<?xml version=""1.0""?>
<Query xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://enterprisedata.com.au/readinow/v2/query/2.0"">
  <Conditions>
    <Condition>
      <Expression>
        <NodeId>b297bec5-45d4-4a58-a227-738ecd9f068a</NodeId>
        <Tag1 entityRef=""true"">core:name</Tag1>
        <Tag2 entityRef=""true""></Tag2>
        <Tag3 entityRef=""true""/>
        <Tag4 entityRef=""true"">12345</Tag4>
        <Tag5 entityRef=""true"">12345</Tag5>
        <TypedValue type=""ChoiceRelationship"" entityRef=""true"">25167<SourceEntityTypeId entityRef=""true"">24704</SourceEntityTypeId></TypedValue>
        <arguments>
          <argument type=""ChoiceRelationship"" entityRef=""true"">4416<SourceEntityTypeId entityRef=""true"">4533</SourceEntityTypeId></argument>
        </arguments>
      </Expression>
    </Condition>
  </Conditions>
</Query>";
            string expected = @"<?xml version=""1.0""?>
<Query xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://enterprisedata.com.au/readinow/v2/query/2.0"">
  <Conditions>
    <Condition>
      <Expression>
        <NodeId>b297bec5-45d4-4a58-a227-738ecd9f068a</NodeId>
        <Tag1 entityRef=""true"">*core:name*</Tag1>
        <Tag2 entityRef=""true""></Tag2>
        <Tag3 entityRef=""true""/>
        <Tag4 entityRef=""true"">*12345*</Tag4>
        <Tag5 entityRef=""true"">*12345*</Tag5>
        <TypedValue type=""ChoiceRelationship"" entityRef=""true"">*25167*<SourceEntityTypeId entityRef=""true"">*24704*</SourceEntityTypeId></TypedValue>
        <arguments>
          <argument type=""ChoiceRelationship"" entityRef=""true"">*4416*<SourceEntityTypeId entityRef=""true"">*4533*</SourceEntityTypeId></argument>
        </arguments>
      </Expression>
    </Condition>
  </Conditions>
</Query>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(before);

            EntityRefHelper.VisitEntityRefTextNodes(doc, node => { node.Value = "*" + node.Value + "*"; });
            string actual = doc.OuterXml;

            XmlDocument doc2 = new XmlDocument();

            doc2.LoadXml(expected);
            string expected2 = doc2.OuterXml;

            Assert.AreEqual(expected2, actual);
        }
Пример #2
0
        /// <summary>
        ///     Remaps the XML entities.
        /// </summary>
        /// <param name="entityUpgradeId">The entity upgrade unique identifier.</param>
        /// <param name="fieldUpgradeId">The field upgrade unique identifier.</param>
        /// <param name="xml">The XML.</param>
        /// <returns></returns>
        public string RemapXmlEntities(Guid entityUpgradeId, Guid fieldUpgradeId, string xml)
        {
            if (xml == null)
            {
                return(null);
            }

            if (xml.Trim( ) == string.Empty)
            {
                return(xml);
            }

            try
            {
                using (var stringReader = new StringReader(xml))
                {
                    XDocument doc = XDocument.Load(stringReader, LoadOptions.SetLineInfo);

                    IEnumerable <XElement> candidates = EntityRefHelper.GetEntityRefTextNodes(doc);

                    IList <XElement> xmlTextNodes = candidates as IList <XElement> ?? candidates.ToList( );

                    if (candidates != null && xmlTextNodes.Count > 0)
                    {
                        if (ConversionMode == XmlConversionMode.LocalIdToUpgradeGuid)
                        {
                            ConvertFromLocalIdToUpgradeId(entityUpgradeId, fieldUpgradeId, xmlTextNodes);
                        }
                        else if (ConversionMode == XmlConversionMode.UpgradeGuidToLocalId)
                        {
                            ConvertFromUpgradeIdToLocalId(entityUpgradeId, fieldUpgradeId, xmlTextNodes);
                        }
                    }

                    return(doc.ToString( ));
                }
            }
            catch (Exception exc)
            {
                EventLog.Application.WriteError("Failed to remap xml entities. " + exc);
                return(xml);
            }
        }