XML parsing in Remote Provisioning ProvisioningTemplate.

Copper Contributor

Hi All,

 

I encountered an issue when trying to save off a template using ProvisioningTemplate.  Whenever I have a custom column or list name with non-xmlable characters in them I get an exception XmlException was unhandled.  The expected token is ;

 

This happens when a List name for export to xml is something like "R&D 2016" to me a perfectly valid name and one our customers use often.  This occurs when I try to do GetProvisioningTemplate to the site containing the list.  I was surprised to see in the feb 10 release of the PNP library that there isn't a SecurityElement.Escape (string) call in XExtensions.cs (

namespace OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml)  when making calls to things like ToXElement(String xml);  WHen I replace with '&' with '&' the string parses just fine.  I'm not sure where to fix on the return trip for writing back to sharepoint yet.

 

I'm new to Sharepoint, is there a best practice not to use un-escaped characters in lists and fields and that's why escaping isn't done?

 

Thank you.

 

 

 

3 Replies

Seems SecurityElement.Escape  isn't the solution it also replaces <>   :(   

There's no best practice describing you should not use un-escaped characters. There are some character limitations in naming SharePoint elements but the GetProvisioningTemplate method should just work with any allowed character.

 

I'd suggest you to submit an issue in the OfficeDevPnP.Core repository on GitHub so you, me or someone else can take a look at it and fix it :)

 

https://github.com/SharePoint/PnP-Sites-Core

 

 

I did more digging and have a better understanding of the issue.  In cases where we have a custom column assocaited with a list that has a non xmlable character in it E.g. List title = "2016 R&D", the PNP code will try to put a token into the SourceID to replace the Guid that associates the column with the list.  So in this case SourceID was a GUID it becomes "{{listid:{list.Title}}}"  which is "listid: 2016 R&D".  This can't be handled by xml parser later on when writing it to disk.  I am testing a fix that when the PNP code reads the lists from CSOM for the site it fixes up the Title to be xmlable so & becomes &amp; etc...  Worked to serialize to disk, am working on the round trip. 

 

private string ParseFieldSchema(string schemaXml, Web web, List<List> lists)
        {
            foreach (var list in lists)
            {
                schemaXml = Regex.Replace(schemaXml, list.Id.ToString(), $"{{listid:{list.Title}}}", RegexOptions.IgnoreCase);
.