0

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?

4

1 回答 1

1

这也不例外,AppSettings.GetxmlWriter.WriteStartElement具有签名:

public void WriteStartElement(
    string localName
)

因此,localName它只是开始 XML 标记的名称,不能包含空格 ( ' ')。但是还有其他重载,您可能对以下内容感兴趣:

public void WriteStartElement(
    string localName,
    string ns
)

其中ns

与元素关联的命名空间 URI。如果这个命名空间已经在范围内并且有一个关联的前缀,那么作者也会自动写入该前缀。

于 2014-07-28T20:59:14.677 回答