I have a sample to read a xml schema set for a xml file which contains different namespaces. For this i can get different schema for each namespace as i explained below.

Sample File:

<?xml version="1.0" encoding="utf-8"?>
<data xmlns:d="http://sampleschema/dataservices" xmlns:m="http://sampleschema/dataservices/metadata">
 <content>
  <m:properties>
   <d:CustomerID>ALFKI</d:CustomerID>
   <d:CompanyName>Alfreds Futterkiste</d:CompanyName>
  </m:properties>
 </content>
</data>

Sample Code to get XML Schema Set:

strFileName = @"C:\Sample\Sample.xml";
XmlReader reader = XmlReader.Create(strFileName);
XmlSchemaInference schema = new XmlSchemaInference();
XmlSchemaSet schemaSet = schema.InferSchema(reader);

It gives three different types of schemas while using the above code. But my requirement will be i need a single schema for the entire xml file which contain any number of namespaces in it. I have checked with possibilities of codes in msdn and stack overflow. I can't find any proper solution for this.

The expected schema output will be like below.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
       <xs:element name="data">
              <xs:complexType>
                     <xs:sequence>
                            <xs:element name="content">
                                   <xs:complexType>
                                          <xs:sequence>
                                                 <xs:element name="m:properties">
                                                        <xs:complexType>
                                                               <xs:sequence>
                                                                      <xs:element name="d:CustomerID" type="xs:string"></xs:element>
                                                                      <xs:element name="d:CompanyName" type="xs:string"></xs:element>
                                                                  </xs:sequence>
                                                           </xs:complexType>
                                                    </xs:element>
                                             </xs:sequence>
                                      </xs:complexType>
                               </xs:element>
                        </xs:sequence>
                     <xs:attribute name="xmlns:d" type="xs:string"></xs:attribute>
                     <xs:attribute name="xmlns:m" type="xs:string"></xs:attribute>
                 </xs:complexType>
          </xs:element>
   </xs:schema>

Any one can help to achieve this requirement.

Thanks in advance.

1

There are 1 answers

2
jdweng On

Try something like this :

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:m="http://www.w3.org/2001/XMLSchema" xmlns:d="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="data">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="content">
          <m:complexType>
            <m:sequence>
              <m:element name="properties">
                <d:complexType>
                  <d:sequence>
                    <d:element name="CustomerID" type="xs:string"></d:element>
                    <d:element name="CompanyName" type="xs:string"></d:element>
                  </d:sequence>
                </d:complexType>
              </m:element>
            </m:sequence>
          </m:complexType>
        </xs:element>
      </xs:sequence>
      <d:attribute name="xmlns_d" type="d:string"></d:attribute>
      <m:attribute name="xmlns_m" type="d:string"></m:attribute>
    </xs:complexType>
  </xs:element>
</xs:schema>