c#/ xml/ exception/ webconfigurationmanager

I am very new to working with XML. I've been weeding my way through debugging a project that was handed to me, but have run into quite a wall.

My code:

XmlWriter xmlWriter = XmlWriter.Create("ToPost.xml");

    xmlWriter.WriteStartDocument();
    xmlWriter.WriteStartElement("eclRequest xmlns='" + WebConfigurationManager.AppSettings.Get("urlAddress") + "'");
    .....

But the WebConfigurationManager.AppSettings.Get("urlAddress") is giving me the following Exception:

Invalid name character in 'eclRequest xmlns='''. The ' ' character, hexadecimal value 0x20, cannot be included in a name.

I was wondering what exactly this Get() statement is accessing, and what could be causing the Exception?

This is not exception of AppSettings.Get but of xmlWriter.WriteStartElement , which has signature:

public void WriteStartElement(
    string localName
)

and hence, localName is just name of start XML tag, cannot contain space ( ' ' ). But there are other overloads , you are probably interested in:

public void WriteStartElement(
    string localName,
    string ns
)

where ns :

The namespace URI to associate with the element. If this namespace is already in scope and has an associated prefix, the writer automatically writes that prefix also.

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Caching of WebConfigurationManager.AppSettings? Cannot retrive a value using WebConfigurationManager.AppSettings WebConfigurationManager Override WebConfigurationManager.AppSettings[“SomeProperty”] dynamically during execution Read appSettings section from Web.config file using WebConfigurationManager Where does WebConfigurationManager.AppSettings write its data? Not to web.config How to convert System.Web.Configuration.WebConfigurationManager.AppSettings from String to INT WebConfigurationManager is unrecognized Get appSettings configSource from code ConfigurationManager.AppSettings[“SMTP”]; null exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM