umco / umbraco-property-list

Property List - a repeatable list (of selected datatype) for Umbraco 7.6+
https://our.umbraco.com/projects/backoffice-extensions/property-list/
MIT License
7 stars 2 forks source link

Compatibility with Tuples (XML format) #12

Open dnwhte opened 5 years ago

dnwhte commented 5 years ago

Hello,

Looking for a bit of direction on resolving this issue.

I have a Property List that is using tuples: image

It works fine when used in an innercontent component (json format), but not when used directly on a doctype (xml format).

I get the following error.

[XmlException: Data at the root level is invalid. Line 1, position 1.]
   System.Xml.XmlTextReaderImpl.Throw(Exception e) +91
   System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() +408
   System.Xml.XmlTextReaderImpl.ParseDocumentContent() +473
   System.Xml.XmlReader.MoveToContent() +118
   System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options) +33
   System.Xml.Linq.XElement.Parse(String text, LoadOptions options) +156
   Our.Umbraco.Tuple.ValueConverters.TupleValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview) +232
   Our.Umbraco.PropertyList.ValueConverters.PropertyListValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview) +561
   Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value() +74
   Umbraco.Web.PublishedPropertyExtension.GetValue(IPublishedProperty property, Boolean withDefaultValue, T defaultValue) +123
   Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias) +75

Stored XML looks like:

        <footerSocialLinks>
          <values dtd="2f2b94f6-062d-4ec9-bb3f-9d768d42d238">
            <value>
              <values>
                <value udi="umb://data-type/cf8919ffc5cd408f8eac7e0909ed7588"><![CDATA[Facebook]]></value>
                <value udi="umb://data-type/0cc0eba1996042c9bf9b60e150b429ae"><![CDATA[]]></value>
              </values>
            </value>
            <value>
              <values>
                <value udi="umb://data-type/cf8919ffc5cd408f8eac7e0909ed7588"><![CDATA[Instagram]]></value>
                <value udi="umb://data-type/0cc0eba1996042c9bf9b60e150b429ae"><![CDATA[]]></value>
              </values>
            </value>
            <value>
              <values>
                <value udi="umb://data-type/cf8919ffc5cd408f8eac7e0909ed7588"><![CDATA[Twitter]]></value>
                <value udi="umb://data-type/0cc0eba1996042c9bf9b60e150b429ae"><![CDATA[]]></value>
              </values>
            </value>
            <value>
              <values>
                <value udi="umb://data-type/cf8919ffc5cd408f8eac7e0909ed7588"><![CDATA[Youtube]]></value>
                <value udi="umb://data-type/0cc0eba1996042c9bf9b60e150b429ae"><![CDATA[]]></value>
              </values>
            </value>
            <value>
              <values>
                <value udi="umb://data-type/cf8919ffc5cd408f8eac7e0909ed7588"><![CDATA[Snapshat]]></value>
                <value udi="umb://data-type/0cc0eba1996042c9bf9b60e150b429ae"><![CDATA[]]></value>
              </values>
            </value>
          </values>
        </footerSocialLinks>

I believe this is an issue with Property List and not Tuples, because a single tuple works fine directly on the doctype.

Thanks!

leekelleher commented 4 years ago

Hi @dnwhte. Hmmm, trying to remember how Property List code works 🤔

Looking at the XML data, the nested <value> elements may be causing an issue.

This line... https://github.com/umco/umbraco-property-list/blob/develop/src/Our.Umbraco.PropertyList/ValueConverters/PropertyListValueConverter.cs#L56 ... is calling XPathSelectElements("value"), which might be gobbling up the Tuple values too? (That's purely guesswork)

If you're building from source, then you could try tweaking that line to be something like...

items.AddRange(elements.XPathSelectElements("./value").Select(x => x.Value));

That should restrict the XPath to use the immediate <value> elements.


In other news... is "Snapshat" a typo, or satire? 😉

dnwhte commented 4 years ago

Well, that's not the issue. However it does appear to be with that line.

It seems a different selection is needed depending on the type that is being repeated.

Ex. Works for property lists repeating simple types items.AddRange(elements.XPathSelectElements("./value").Select(x => x.Value));

Ex. Works for property lists repeating a tuple items.AddRange(elements.XPathSelectElements("./value/values"));

XML for a couple types of property lists. The last one is a tuple. image


ha...It's a typo, but I wish I had thought of it 😁.