5

我需要生成这样的东西:

<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>

这并不是我想要的。有什么想法,应该做些什么不同的事情?

4

1 回答 1

0

问题已经在这里解决了:

如何添加 xml 命名空间(Amazon Envelope)

于 2012-06-14T22:09:59.177 回答