我通过 xsd.exe 工具从模式生成了一个类
xmlns=""
现在,当我对课程进行序列化时,我会在根目录下的所有内容上获得额外信息。
<myroot xmlns="blabla">
<tag1 xmlns="">
<tag2>
...
架构如下所示:
<xsd:schema xmlns="blabla" targetNamespace="blabla" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MyRoot">
我在架构中看不到任何内容,表明 tag1 元素及以下元素应该位于根目录之外的另一个命名空间中。
序列化代码只是做:
MyRoot doc = new MyRoot();
...
XmlSerializer xs = new XmlSerializer(typeof(MyRoot));
MemoryStream ms = new MemoryStream();
try {
xs.Serialize(ms, doc);
从 xsd.exe 生成的类只包含根类的命名空间属性。