예제 #1
0
 private string GetSerializedItem72(Item sourceItem, bool recurse, TransferOptions transferOptions)
 {
     var options = ItemSerializerOptions.GetDefaultOptions();
     options.AllowDefaultValues = transferOptions.HasFlag(TransferOptions.AllowDefaultValues);
     options.AllowStandardValues = transferOptions.HasFlag(TransferOptions.AllowStandardValues);
     options.ProcessChildren = recurse;
     return sourceItem.GetOuterXml(options);
 }
예제 #2
0
 private string GetSerializedItemOld(Item sourceItem, bool recurse)
 {
     return sourceItem.GetOuterXml(recurse);
 }
예제 #3
0
        private static string GetSlimXml(Item i)
        {
            var doc = XDocument.Parse(i.GetOuterXml(true));
            var systemFields = doc.Descendants("field").Where(x => x.Attribute("key").Value.StartsWith("__")
                                                            || string.IsNullOrEmpty(x.Attribute("key").Value));
            systemFields.Remove();

            // Remove other languages
            var otherLanguages = doc.Descendants("version").Where(x => x.Attribute("language").Value != i.Language.Name).ToArray();
            foreach (var v in otherLanguages)
                v.Remove();

            // Remove other versions
            var otherVersions = doc.Descendants("version").Where(x => x.Attribute("version").Value != i.Version.Number.ToString()).ToArray();
            foreach (var v in otherVersions)
                v.Remove();

            foreach (var version in doc.Descendants("version"))
            {
                var sortedFields = version.Element("fields")
                                          .Elements("field")
                                          .OrderBy(x => x.Attribute("tfid").Value)
                                          .ToArray();

                foreach (var f in sortedFields)
                    f.Remove();
                foreach (var f in sortedFields)
                    version.Element("fields").Add(f);
            }
            return doc.ToString();
        }