Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带空格的C#XAttribute_C#_.net_Linq_Xml Parsing_Linq To Xml - Fatal编程技术网

带空格的C#XAttribute

带空格的C#XAttribute,c#,.net,linq,xml-parsing,linq-to-xml,C#,.net,Linq,Xml Parsing,Linq To Xml,如何在XAttribute上使用空格,以下是我的代码片段: new XElement("SubstitutionAttribute", new XAttribute("SubNetwork Group",subNetBox.Text)) 我试图在xml中实现的目标: <SubstitutionAttribute name="SubNetwork Group" value="Something" /> 致以最良好的祝愿 Hugo示例失败的原因是XAttribute的构造函数需要

如何在XAttribute上使用空格,以下是我的代码片段:

new XElement("SubstitutionAttribute", new XAttribute("SubNetwork Group",subNetBox.Text))
我试图在xml中实现的目标:

<SubstitutionAttribute name="SubNetwork Group" value="Something" />

致以最良好的祝愿


Hugo

示例失败的原因是
XAttribute
的构造函数需要属性的名称及其值

因此,使用
new-XElement(“SubstitutionAttribute”,new-XAttribute(“SubNetwork Group”,subNetBox.Text))
实际上只声明了一个名为“SubNetwork Group”且值为subNetBox.Text(
)的属性。这是无效的XML,因为属性名称中不能有空格

我认为您正在尝试使用两个属性来完成—一个名为
name
,另一个名为
value

new XElement("SubstitutionAttribute", 
    new XAttribute("name", "SubNetwork Group"), 
    new XAttribute("value", subNetBox.Text));

示例失败的原因是
XAttribute
的构造函数需要属性的名称及其值

因此,使用
new-XElement(“SubstitutionAttribute”,new-XAttribute(“SubNetwork Group”,subNetBox.Text))
实际上只声明了一个名为“SubNetwork Group”且值为subNetBox.Text(
)的属性。这是无效的XML,因为属性名称中不能有空格

我认为您正在尝试使用两个属性来完成—一个名为
name
,另一个名为
value

new XElement("SubstitutionAttribute", 
    new XAttribute("name", "SubNetwork Group"), 
    new XAttribute("value", subNetBox.Text));