有没有简单的方法可以从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中指定命名空间有什么用呢?我不太理解。