1

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

svick
  • 236,525
  • 50
  • 385
  • 514
arva
  • 75
  • 2
  • 8

1 Answers1

5

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.

svick
  • 236,525
  • 50
  • 385
  • 514
  • Thank, you. But I would like have URL in LogOn element in original format. Not edit text inside...It exist way? – arva Mar 04 '12 at 16:32
  • No, you can't (unless you want to use CDATA). That's just you how you represent `&` in XML. Why would you want to have in “original format”? – svick Mar 04 '12 at 16:35
  • I will try CDATA method..because is not comfortable edit manualy & for normal users. Method put url inside [CDATA[URL]] is more clear then put amp behind &. – arva Mar 04 '12 at 18:59