C# 如何使用XmlSampleGenerator将一个xsd文件中的xmlElement添加到另一个xsd文件的xmlElement中?

C# 如何使用XmlSampleGenerator将一个xsd文件中的xmlElement添加到另一个xsd文件的xmlElement中?,c#,xml,xsd,C#,Xml,Xsd,我使用XmlSampleGenerator从xsd生成xml文件。我能够直接使用下面的代码从单个xsd文件生成xml文件 using (var stream = new MemoryStream(File.ReadAllBytes("platform-container.xsd"))) { var schema = XmlSchema.Read(XmlReader.Create(stream), null); var gen = n

我使用XmlSampleGenerator从xsd生成xml文件。我能够直接使用下面的代码从单个xsd文件生成xml文件

using (var stream = new MemoryStream(File.ReadAllBytes("platform-container.xsd")))
        {
            var schema = XmlSchema.Read(XmlReader.Create(stream), null);
            var gen = new XmlSampleGenerator(schema, new XmlQualifiedName("Document"));
            gen.WriteXml(XmlWriter.Create(@"C:\SCIP\SCIP-Phase-1\SCIPAppPrj\XmlFiles\dossier.i6d"));
            Console.WriteLine("Autogenerated file is here : C:\\SCIP\\SCIP-Phase-1\\SCIPAppPrj\\XmlFiles\\dossier.i6d");
        }
但是当我必须组合来自多个xsd文件的元素并生成一个xml文件时,我就面临着这个问题。 例如,我生成的xml应该如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<i6c:Document xmlns:i6c="http://iuclid6.echa.europa.eu/namespaces/platform-container/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://iuclid6.echa.europa.eu/namespaces/platform-container/v1 container.xsd">
   <i6c:PlatformMetadata xmlns:i6m="http://iuclid6.echa.europa.eu/namespaces/platform-metadata/v1" xsi:schemaLocation="http://iuclid6.echa.europa.eu/namespaces/platform-container/v1 container.xsd">
     <i6m:iuclidVersion>1.0</i6m:iuclidVersion>
     <i6m:documentKey>ABC</i6m:documentKey>
     <i6m:documentType>DOSSIER</i6m:documentType>
  </i6c:PlatformMetadata>
  <i6c:Content>
     <DOSSIER.SCIP xmlns="http://iuclid6.echa.europa.eu/namespaces/DOSSIER-SCIP/1.0" xmlns:i6="http://iuclid6.echa.europa.eu/namespaces/platform-fields/v1" />
  </i6c:Content>
</i6c:Document>

1
基础知识
档案
我有一个名为container.xsd的主xsd,它有xml文件的框架。还包括metaData.xsd和content.xsd,其中包含的元素应作为子元素包含在container.xsd中的某个元素下

container.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://iuclid6.echa.europa.eu/namespaces/platform-container/v1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://iuclid6.echa.europa.eu/namespaces/platform-container/v1"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:element name="Document">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="PlatformMetadata">
                <xs:complexType>
                    <xs:sequence maxOccurs="unbounded">
                        <xs:any namespace="##other" processContents="lax" minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="Content">
                <xs:complexType>
                    <xs:sequence>
                        <xs:any namespace="##other" processContents="strict" minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

metaData.xsd

<xs:schema xmlns="http://iuclid6.echa.europa.eu/namespaces/platform-metadata/v1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://iuclid6.echa.europa.eu/namespaces/platform-metadata/v1"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:element name="iuclidVersion" type="xs:string">
</xs:element>
<xs:element name="documentKey" type="xs:string">
</xs:element>
<xs:element name="documentType" type="xs:string">
</xs:element>
</xs:schema>

content.xsd

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://iuclid6.echa.europa.eu/namespaces/DOSSIER-SCIP/1.0" xmlns:ct="http://iuclid6.echa.europa.eu/namespaces/scip/v1" xmlns:i6="http://iuclid6.echa.europa.eu/namespaces/platform-fields/v1" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://iuclid6.echa.europa.eu/namespaces/DOSSIER-SCIP/1.0">
<xs:import namespace="http://iuclid6.echa.europa.eu/namespaces/platform-fields/v1" schemaLocation="platform-fields.xsd"/>
<xs:import namespace="http://iuclid6.echa.europa.eu/namespaces/scip/v1" schemaLocation="commonTypesScipV1.xsd"/>
<xs:element name="DOSSIER.SCIP">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="remarks" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

有人能建议我如何使用XmlSampleGenerator处理这个问题吗?如何从多个xsd和一个xml文件中读取元素?如何为每个元素添加数据