Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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/3/arrays/13.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#XmlReader冒号问题(名称空间)_C#_Feed_Atom Feed - Fatal编程技术网

C#XmlReader冒号问题(名称空间)

C#XmlReader冒号问题(名称空间),c#,feed,atom-feed,C#,Feed,Atom Feed,我对XMLReader类有一个奇怪的问题。我从一个URL获取atom提要,xml树的一些元素命名如下: <element:title>Hello World!</element:title> <element:text>This is just an example</element:text> <element:id>1</element:id> 但这是行不通的。当我浏览代码时,我看到读者将其解析为 element_x0

我对XMLReader类有一个奇怪的问题。我从一个URL获取atom提要,xml树的一些元素命名如下:

<element:title>Hello World!</element:title>
<element:text>This is just an example</element:text>
<element:id>1</element:id>
但这是行不通的。当我浏览代码时,我看到读者将其解析为

element_x003A_id
但是如果我使用

[XmlElement("element_x003A_id)]

我什么也得不到。我尝试过修改Xml编码,但该属性是只读的。如何转义它,以便获取元素的内容(如果元素没有分号,它就可以正常工作)?

元素
是名称空间别名。在某个地方,你有(通常在文件的顶部)

或者因为它将被重复使用:

const string MyNamespace = "http://something/blah/blog";
//...
[XmlElement("id", Namespace=MyNamespace)]
public int Id {get;set;}

元素
是命名空间别名。在某个地方,你有(通常在文件的顶部)

或者因为它将被重复使用:

const string MyNamespace = "http://something/blah/blog";
//...
[XmlElement("id", Namespace=MyNamespace)]
public int Id {get;set;}

请参阅此链接:顺便说一句,
是冒号;分号是
是冒号;分号是
Marc你说得对,睡眠剥夺是无声的杀手。谢谢你,我很不好意思错过了这么基本的东西。@Anonymous仅供记录,别名
元素
除了对读者以外没有什么意义;另一个文件完全可以合法地使用
xmlsn:evil=…
——并且数据是相同的。这就是为什么
[xmlement(…)]
知道名称空间,但不需要知道别名。事实上,你甚至不需要别名;它可能是
,但仍然是完全相同的数据。感谢您的澄清,添加名称空间的工作非常完美。谢谢您,我很不好意思错过了如此基本的内容。@Anonymous仅供记录,别名
元素
除了对读者以外并不重要;另一个文件完全可以合法地使用
xmlsn:evil=…
——并且数据是相同的。这就是为什么
[xmlement(…)]
知道名称空间,但不需要知道别名。事实上,你甚至不需要别名;它可能是
,但仍然是完全相同的数据。感谢您的澄清,添加名称空间非常有效。
[XmlElement("id", Namespace="http://something/blah/blog")]
public int Id {get;set;}
const string MyNamespace = "http://something/blah/blog";
//...
[XmlElement("id", Namespace=MyNamespace)]
public int Id {get;set;}