5

While trying to create a new configuration setting whose value is a string consisting of one double quote ("), the following exception is thrown:

28240 19:25:51 ERROR Could not load configuration file: C:\inetpub\wwwroot\sitename\Website\App_Config\Include\EzImporter\Sitecore.EzImporter.config: System.Xml.XPath.XPathException: This is an unclosed string.
   at MS.Internal.Xml.XPath.XPathScanner.ScanString()
   at MS.Internal.Xml.XPath.XPathScanner.NextLex()
   at MS.Internal.Xml.XPath.XPathParser.ParsePrimaryExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseFilterExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseExpresion(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParsePredicate(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseStep(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseExpresion(AstNode qyInput)
   at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion)
   at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
   at System.Xml.XPath.XPathNavigator.Compile(String xpath)
   at System.Xml.XmlNode.SelectSingleNode(String xpath, XmlNamespaceManager nsmgr)
   at Sitecore.Xml.Patch.XmlPatchHelper.MergeChildren(XmlNode target, IXmlElement patch, XmlPatchNamespaces ns, Boolean targetWasInserted)
   at Sitecore.Xml.Patch.XmlPatchHelper.MergeChildren(XmlNode target, IXmlElement patch, XmlPatchNamespaces ns, Boolean targetWasInserted)
   at Sitecore.Xml.Patch.XmlPatchHelper.MergeNodes(XmlNode target, IXmlElement patch, XmlPatchNamespaces ns)
   at Sitecore.Configuration.ConfigPatcher.ApplyPatch(TextReader patch, String sourceName)
   at Sitecore.Configuration.ConfigPatcher.ApplyPatch(String filename)
   at Sitecore.Configuration.ConfigReader.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder)

The setting in the config file looks like this:

<setting name="EzImporter.QuotationMark" value="&quot;"/>

Is there a way to escape one double quote in the configuration file?

5

After some additional tests, I manage to achieve the objective.

The right expression is:

<setting name="EzImporter.QuotationMark" set:value="&quot;"/>

Notice that the attribute "value" has been replaced by "set:value". The set prefix also needs its associated xml namespace: xmlns:set="http://www.sitecore.net/xmlconfig/set/"

The final code is as follow:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <settings>
      ...
      <setting name="EzImporter.QuotationMark" set:value="&quot;"/>
      ...
    </settings>
  </sitecore>
</configuration>

The reason why it was failing was due to the mechanism performed by Sitecore to merge several configuration files. Internally it checks the setting already exists and it uses an XPath expression such as 'setting[@name="EzImporter.QuotationMark" and @value="""]', is causes the exception.

By replacing the "value" attribute by "set:value" the XPath expression ignores the double quot.

I hope it helps somebody else.

2
  • 1
    Interesting... I'm not getting this behavior. Which version of Sitecore are you using? Also note that you could use single quotes instead to avoid escaping your double quote: set:value='"' – maz Aug 31 '18 at 19:13
  • 1
    @maz I don't think it depends on Sitecore versions because I once had the same issue. On local instance we were using Sitecore 8.2 U1 and on our Prod Env it was the same Sitecore version. It worked on local instance but not on Prod. – Hishaam Namooya Aug 31 '18 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.