如何从 XML 根元素中删除命名空间?
有没有一种简单的方法可以从 XML 根元素中删除名称空间。我尝试过
[XmlRootAttribute("MCP", Namespace = "", IsNullable = false)]
可序列化类。但没有用。仍然得到相同的结果。
示例类
[Serializable]
[XmlRootAttribute("MCP", Namespace = "", IsNullable = false)]
public class BINDRequest
{
public BINDRequest()
{
}
[XmlAttribute]
public string CLIENT_REQUEST_ID { get; set; }
public BINDRequestBody BIND { get; set; }
}
结果 xml
<?xml version="1.0" encoding="utf-8"?>
<MCP xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" CLIENT_REQUEST_ID="1">
<BIND CLIENT_ID="test" PASSWORD="test" />
</MCP>
我不明白那么在 XmlRootAttribute 中指定 namsespace 有什么用?
is there a simple way to remove the namespace from the XML root element. I have tried with
[XmlRootAttribute("MCP", Namespace = "", IsNullable = false)]
on the serializable class. But no use. still getting the same result.
sample class
[Serializable]
[XmlRootAttribute("MCP", Namespace = "", IsNullable = false)]
public class BINDRequest
{
public BINDRequest()
{
}
[XmlAttribute]
public string CLIENT_REQUEST_ID { get; set; }
public BINDRequestBody BIND { get; set; }
}
result xml
<?xml version="1.0" encoding="utf-8"?>
<MCP xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" CLIENT_REQUEST_ID="1">
<BIND CLIENT_ID="test" PASSWORD="test" />
</MCP>
i don't understand then whats the use of specifying namsespace in XmlRootAttribute??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: