如何分析复杂类型中具有复杂内容和扩展名的 XSD

本文关键字:复杂 扩展名 XSD 类型 | 更新日期: 2023-09-27 18:33:39

我正在尝试从给定的XSD中检索属性列表。我能够获得几乎所有属性简单和复杂类型。但是我无法检索设置了扩展名和复杂内容的那些架构元素的属性。 我在 C# 中使用 XmlSchemaComplexContent 和 XmlSchemaComplexContentExtension 类尝试了不同的东西,但可能是我没有正确使用它们,任何人都可以为我提供有关如何使用这些类的指南或一些适当的 xsd 解析教程。

我想提取这些序列元素.

<xs:element name="xyz" type="xyz"/>
<xs:complexType name="xyz">
<xs:complexContent>
  <xs:extension base="robj">
    <xs:sequence>
        <xs:element name="xyzHierarchy" type="rnb_v1_2:NList" />
        <xs:element name="Attributes" type="xyzOptions" />
        <xs:element name="Country" type="riD" />
        <xs:element name="CustomFields" />
        <xs:element name="DisplayName" type="xs:string" />
        <xs:element name="DisplayOrder" type="xs:int"/>
            <xs:element name="Signature" type="xs:string" nillable="true"/>
    </xs:extension>
   </xs:complexContent>

如何分析复杂类型中具有复杂内容和扩展名的 XSD

我得到了答案。我想与大家分享。其中 toFile 是字符串类型在这里,我只是编写了执行特定任务的代码部分,而不是整个代码。///////////////////////////////////////////////////////////////////////////////////////////

private static void main(String[] args)
if (complexType != null)
                    {  
                        XmlSchemaParticle particle = complexType.Particle;
                        XmlSchemaSequence sequence = particle as XmlSchemaSequence;
                        toFile = toFile + "Complex  " + complexType.Name;
                        toFile = toFile + "'n";
                        if (complexType.ContentModel != null)
                        {
                            xmlComplexContent = (XmlSchemaComplexContent)complexType.ContentModel;
                            if (complexType != null)
                            {
                                extension = (XmlSchemaComplexContentExtension)xmlComplexContent.Content;
                                extension.BaseTypeName = complexType.QualifiedName;  // base name 
                                sequence =(XmlSchemaSequence) extension.Particle;
                                if (extension.BaseTypeName.Name != null)
                                {
                                    if (sequence != null)
                                    {
                                        Out(extension.Particle);   
                                    }
                                }
                            }
                        }
                      else
                            Out(complexType.Particle);
                }
      System.IO.File.WriteAllText(@"C:''Users''KAMALPREETDEV''Desktop''attributes.txt", toFile);
        }
        private static void Out(XmlSchemaParticle particle)
        {
            XmlSchemaSequence sequence = particle as XmlSchemaSequence;
            XmlSchemaChoice choice = particle as XmlSchemaChoice;
            XmlSchemaAll all = particle as XmlSchemaAll;
            if (sequence != null)
            {
                toFile = toFile + "  Sequence";
                toFile = toFile + "'n";
                for (int i = 0; i < sequence.Items.Count; i++)
                {
                    XmlSchemaElement childElement = sequence.Items[i] as XmlSchemaElement;
                    XmlSchemaSequence innerSequence = sequence.Items[i] as XmlSchemaSequence;
                    XmlSchemaChoice innerChoice = sequence.Items[i] as XmlSchemaChoice;
                    XmlSchemaAll innerAll = sequence.Items[i] as XmlSchemaAll;
                    if (childElement != null)
                    {
                        toFile = toFile + "    Element/Type:  " + childElement.Name + "/" + childElement.SchemaTypeName.Name;
                        toFile = toFile + "'n";
                    }
                    else Out(sequence.Items[i] as XmlSchemaParticle);
                }
            }