Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

How to add the xmlElement from one xsd file within the xmlElement of another xsd file using XmlSampleGenerator?

$
0
0

Hi,

I'm using XmlSampleGenerator to generate the xml file from xsd. I'm able to generate the xml file from single xsd file directly using bellow code.

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");
        }

But I'm facing the issue when I have to combine the elements from multiple xsd files and generate one single xml file. For example my generated xml should look like below:

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


I have main xsd called container.xsd, which has skeleton for my xml file. Also metaData.xsd and content.xsd which contains elements that should be included as a child under one of the element present in 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>

Can anyone suggest me how to handle this using XmlSampleGenerator? How to read the elements from multiple xsd's and genrate single xml file ? How to append the data for each element ? And How to loop through repeatable element ?

Thanks and Regards,

Bhavya


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>