我需要生成这样的东西:
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
...
</Header>
</AmazonEnvelope>
我正在尝试这样的事情,但它并不完全正确:
XmlSerializerNamespaces nms = new XmlSerializerNamespaces();
nms.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nms.Add("noNamespaceSchemaLocation", "amzn-envelope.xsd");
XmlSerializer serializer = new XmlSerializer(typeof(XMLAmazonEnvelope));
StreamWriter writer = new StreamWriter(path);
serializer.Serialize(writer, objectToSave,nms);
writer.Close();
结果是:
<?xml version="1.0" encoding="utf-8"?>
<xsi:AmazonEnvelope xmlns:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsi:Header>
...
</xsi:Header>
</xsi:AmazonEnvelope>
这并不是我想要的。有什么想法,应该做些什么不同的事情?