diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs index d9ee6aa805..5de94f6749 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs @@ -374,57 +374,62 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache _isDraft = (_xmlNode.Attributes.GetNamedItem("isDraft") != null); } - // load data - //var dataXPath = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema ? "data" : "* [not(@isDoc)]"; - //var nodes = _xmlNode.SelectNodes(dataXPath); - var nodes = new List(); + //dictionary to store the property node data + var propertyNodes = new Dictionary(); - var legacy = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema; + var legacy = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema; foreach (XmlNode n in _xmlNode.ChildNodes) { var e = n as XmlElement; if (e == null) continue; if (legacy) { - if (n.Name == "data") nodes.Add(n); - else break; - } + if (n.Name == "data") + { + PopulatePropertyNodes(propertyNodes, e); + } + else break; //we are not longer on property elements + } else { - if (e.HasAttribute("isDoc") == false) nodes.Add(n); - else break; + if (e.HasAttribute("isDoc") == false) + { + PopulatePropertyNodes(propertyNodes, e); + } + else break; //we are not longer on property elements } } - _contentType = PublishedContentType.Get(PublishedItemType.Content, _docTypeAlias); + //lookup the content type and create the properties collection + _contentType = PublishedContentType.Get(PublishedItemType.Content, _docTypeAlias); + _properties = new Dictionary(StringComparer.OrdinalIgnoreCase); - var propertyNodes = new Dictionary(); - if (nodes != null) - foreach (XmlNode n in nodes) - { - var attrs = n.Attributes; - if (attrs == null) continue; - var alias = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema - ? attrs.GetNamedItem("alias").Value - : n.Name; - propertyNodes[alias.ToLowerInvariant()] = n; - } - - _properties = _contentType.PropertyTypes.Select(p => + //fill in the property collection + foreach (var propertyType in _contentType.PropertyTypes) { - XmlNode n; - return propertyNodes.TryGetValue(p.PropertyTypeAlias.ToLowerInvariant(), out n) - ? new XmlPublishedProperty(p, _isPreviewing, n) - : new XmlPublishedProperty(p, _isPreviewing); - }).Cast().ToDictionary( - x => x.PropertyTypeAlias, - x => x, - StringComparer.OrdinalIgnoreCase); + XmlNode n; + var val = propertyNodes.TryGetValue(propertyType.PropertyTypeAlias.ToLowerInvariant(), out n) + ? new XmlPublishedProperty(propertyType, _isPreviewing, n) + : new XmlPublishedProperty(propertyType, _isPreviewing); + + _properties[propertyType.PropertyTypeAlias] = val; + } // warn: this is not thread-safe... _nodeInitialized = true; } + private void PopulatePropertyNodes(IDictionary propertyNodes, XmlNode n) + { + var attrs = n.Attributes; + if (attrs == null) return; + + var alias = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema + ? attrs.GetNamedItem("alias").Value + : n.Name; + propertyNodes[alias.ToLowerInvariant()] = n; + } + private void InitializeChildren() { if (_xmlNode == null) return;