259 messaggi dal 09 marzo 2006
ciao.
Ho trovato e leggermente modificato questo script che enumera gli elementi e gli attributi di un xsd con il som di ms framework 2.0.
Vorrei da questo script estrarre i metadata per creare delle classi c++ a modo mio ,modo che esula dalla domanda perchè sono nella fase di raccolta dei metadata che usero' per creare le classi.
using System;

using System.Collections;

using System.Xml;

using System.Xml.Schema;



class XmlSchemaTraverseExample

{

 static void Main()

 {

  // Add the customer schema to a new XmlSchemaSet and compile it.

  // Any schema validation warnings and errors encountered reading or 

  // compiling the schema are handled by the ValidationEventHandler delegate.

  XmlSchemaSet schemaSet = new XmlSchemaSet();

  //schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);

  schemaSet.Add(null, "c:\\IFC2X3.xsd");

  schemaSet.Compile();



  // Retrieve the compiled XmlSchema object from the XmlSchemaSet

  // by iterating over the Schemas property.

  XmlSchema customerSchema = null;

  foreach (XmlSchema schema in schemaSet.Schemas())

  {

   customerSchema = schema;





   // Iterate over each XmlSchemaElement in the Values collection

   // of the Elements property.

   foreach (XmlSchemaElement element in customerSchema.Elements.Values)

   {



    Console.WriteLine("Element: {0}", element.Name);

    // Get the complex type of the Customer element.

    XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;

    

    

    Console.WriteLine("Base: {0}",element.SubstitutionGroup.Name);

    // If the complex type has any attributes, get an enumerator 

    // and write each attribute name to the console.

    if (complexType.AttributeUses.Count > 0)

    {

     IDictionaryEnumerator enumerator =

      complexType.AttributeUses.GetEnumerator();



     while (enumerator.MoveNext())

     {

      XmlSchemaAttribute attribute =

       (XmlSchemaAttribute)enumerator.Value;



      Console.WriteLine("Attribute: {0}", attribute.Name);

     }

    }



    // Get the sequence particle of the complex type.

    XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;



    // Iterate over each XmlSchemaElement in the Items collection.

    if(sequence != null)

     foreach (XmlSchemaElement childElement in sequence.Items)

     {

      if(childElement.ElementSchemaType.BaseXmlSchemaType.DerivedBy == XmlSchemaDerivationMethod.Empty){

       Console.WriteLine("Element: {0}", childElement.SchemaTypeName.Name);

       Console.WriteLine("Element: {0}", childElement.Name);

     }

    }

   }

  }

 }

 static void ValidationCallback(object sender, ValidationEventArgs args)

 {

  if (args.Severity == XmlSeverityType.Warning)

   Console.Write("WARNING: ");

  else if (args.Severity == XmlSeverityType.Error)

   Console.Write("ERROR: ");



  Console.WriteLine(args.Message);

 }

}

my problem is there:

if(sequence != null)

foreach (XmlSchemaElement childElement in sequence.Items) {

if(childElement.ElementSchemaType.BaseXmlSchemaType.DerivedBy == XmlSchemaDerivationMethod.Empty){

Console.WriteLine("Element: {0}", childElement.SchemaTypeName.Name);

Console.WriteLine("Element: {0}", childElement.Name);

} }

i would find only the not derived properties of the element but the code print all the derived and not derived properties.

vorrei trovare solo le proprietà dell'elemento e non tutte quelle che sono derivate perchè vi è una derivazione di classe.

ad es:

<xs:element substitutionGroup="ifc:IfcControl" name="IfcActionRequest" nillable="true" type="ifc:IfcActionRequest">
    </xs:element>
    <xs:complexType name="IfcActionRequest">
        <xs:complexContent>
            <xs:extension base="ifc:IfcControl">
                <xs:sequence>
                    <xs:element name="RequestID" type="ifc:IfcIdentifier">
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
and

<xs:element substitutionGroup="ifc:IfcObject" name="IfcControl" nillable="true" type="ifc:IfcControl" abstract="true">
    </xs:element>
    <xs:complexType name="IfcControl" abstract="true">
        <xs:complexContent>
            <xs:extension base="ifc:IfcObject">
                            <xs:sequence>
                    <xs:element name="ObjID" type="ifc:xxx">
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>


mi stampa RequestId(OK) e ObjID(NO!!!!) non voglio le proprietà della classe che sono gia state definite nella classe da cui eredito nel qual caso IfcControl.


come posso risolvere?
Modificato da giuseppe500 il 03 marzo 2011 15.43 -

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.
Community
Ultimi messaggi
UTENTI ONLINE
In primo piano

I più letti di oggi

Media
In evidenza
MISC