Question

I use Castle Windsor IoC. I would like configure object in IoC from XML file. Class is only POCO with some properties.

My problem is that value of property is string which contain special characters.

For example here is XML which I use for configure object in IoC.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <components>
    <component id="pokecUrls" 
               type="Pk.Common.Entities.Communication.PkcUrls, Pk.Common" 
               lifestyle="singleton">
      <parameters>

        <LogOn>https://pk.zet.com/overenie?isWap=0&uri=http%3A%2F%2Fpk.zet.com%2F</LogOn>

      </parameters>
    </component>
  </components>
</configuration>

Here is C# code:

_container.Install(Configuration.FromXmlFile("PkcCoreSettings\\PkUrls.xml"));
var urls = _container.Resolve<Pkrls>();
Assert.IsNotNull(urls);

This code crash because element LogOn contains string with specials characters.

I get this error:

{"Error processing node resource FileResource: [PkUrls.xml] [filepath]"}

InnerException:

{"An error occurred while parsing EntityName. Line 11, position 61."}

StackTrace:

  at Castle.Windsor.Configuration.Interpreters.XmlProcessor.XmlProcessor.Process(IResource resource) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\Windsor\Configuration\Interpreters\XmlProcessor\XmlProcessor.cs:line 115
   at Castle.Windsor.Configuration.Interpreters.XmlInterpreter.ProcessResource(IResource source, IConfigurationStore store, IKernel kernel) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\Windsor\Configuration\Interpreters\XmlInterpreter.cs:line 83
   at Castle.Windsor.Installer.ConfigurationInstaller.Castle.MicroKernel.Registration.IWindsorInstaller.Install(IWindsorContainer container, IConfigurationStore store) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\Windsor\Installer\ConfigurationInstaller.cs:line 74
   at Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers, DefaultComponentInstaller scope) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\Windsor\WindsorContainer.cs:line 319

It exist way how can I have special characters in value of XML element and use this XML file for confirure Windows IoC?

I am not sure if it is possible

Was it helpful?

Solution

You need to escape the & as &amp;, because & is special character in XML:

<LogOn>https://pk.zet.com/overenie?isWap=0&amp;uri=http%3A%2F%2Fpk.zet.com%2F</LogOn>

Alternatively, you could write it as CDATA:

<LogOn><![CDATA[https://pk.zet.com/overenie?isWap=0&uri=http%3A%2F%2Fpk.zet.com%2F]]></LogOn>

There are no other characters in that URL that are special in XML.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top