我正在尝试从给定的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>
答案 0 :(得分:1)
我得到了答案。 我想与大家分享。 其中toFile是String类型 在这里,我只编写了执行特定任务而不是整个代码的代码部分。 ////////////////////////////////////////////////// /////////////////////////////////////////
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);
}
}