Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Compatibility with Tuples (XML format) #12

Open
dnwhte opened this issue Sep 20, 2019 · 2 comments
Open

Compatibility with Tuples (XML format) #12

dnwhte opened this issue Sep 20, 2019 · 2 comments

Comments

@dnwhte
Copy link

dnwhte commented Sep 20, 2019

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
Copy link
Collaborator

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
Copy link
Author

dnwhte commented Sep 24, 2019

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 😁.

dnwhte pushed a commit to dnwhte/umbraco-property-list that referenced this issue Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants