[英]C# XmlReader Colon Issues (Namespace)
I have a strange problem with the XMLReader class. 我对XMLReader类有一个奇怪的问题。 I get atom feed from a URL, and some elements of the xml tree are named like these: 我从URL获取原子提要,并且xml树的一些元素命名如下:
<element:title>Hello World!</element:title>
<element:text>This is just an example</element:text>
<element:id>1</element:id>
Im using 我正在使用
[XmlElement("element:id")]
but this is not working. 但这不起作用。 When I look through the code I see that the reader parse this as 当我查看代码时,我看到读者将其解析为
element_x003A_id
but if I use 但是,如果我使用
[XmlElement("element_x003A_id)]
I get nothing. 我一无所获。 I tried fiddling with the Xml encoding, but the property is read-only. 我试图摆弄Xml编码,但该属性是只读的。 How can I escape this, so I can get the content of the elements (if the element does not have semicolon it works just fine)? 我怎么能逃避这个,所以我可以得到元素的内容(如果元素没有分号,它工作得很好)?
element
is a namespace alias. element
是命名空间别名。 Somewhere, you have (at the top of the file, usually) 某处,你有(通常在文件的顶部)
<foo ... xmlns:element="http://something/blah/blog">
the "http://something/blah/blog" is important. “http:// something / blah / blog”非常重要。 Basically, you need: 基本上,你需要:
[XmlElement("id", Namespace="http://something/blah/blog")]
public int Id {get;set;}
Or since it is going to be used repeatedly: 或者因为它将被重复使用:
const string MyNamespace = "http://something/blah/blog";
//...
[XmlElement("id", Namespace=MyNamespace)]
public int Id {get;set;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.