EDN Admin
Well-known member
i find and modify this code:i generate c++ classes with som and i would use my personal class , not any xsd.exe,code syntetys ecc.
<pre>using System;<br/>
using System.Collections;<br/>
using System.Xml;<br/>
using System.Xml.Schema;<br/>
<br/>
class XmlSchemaTraverseExample<br/>
{<br/>
static void Main()<br/>
{<br/>
// Add the customer schema to a new XmlSchemaSet and compile it.<br/>
// Any schema validation warnings and errors encountered reading or <br/>
// compiling the schema are handled by the ValidationEventHandler delegate.<br/>
XmlSchemaSet schemaSet = new XmlSchemaSet();<br/>
//schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);<br/>
schemaSet.Add(null, "c:\IFC2X3.xsd");<br/>
schemaSet.Compile();<br/>
<br/>
// Retrieve the compiled XmlSchema object from the XmlSchemaSet<br/>
// by iterating over the Schemas property.<br/>
XmlSchema customerSchema = null;<br/>
foreach (XmlSchema schema in schemaSet.Schemas())<br/>
{<br/>
customerSchema = schema;<br/>
<br/>
<br/>
// Iterate over each XmlSchemaElement in the Values collection<br/>
// of the Elements property.<br/>
foreach (XmlSchemaElement element in customerSchema.Elements.Values)<br/>
{<br/>
<br/>
Console.WriteLine("Element: {0}", element.Name);<br/>
// Get the complex type of the Customer element.<br/>
XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;<br/>
<br/>
<br/>
Console.WriteLine("Base: {0}",element.SubstitutionGroup.Name);<br/>
// If the complex type has any attributes, get an enumerator <br/>
// and write each attribute name to the console.<br/>
if (complexType.AttributeUses.Count > 0)<br/>
{<br/>
IDictionaryEnumerator enumerator =<br/>
complexType.AttributeUses.GetEnumerator();<br/>
<br/>
while (enumerator.MoveNext())<br/>
{<br/>
XmlSchemaAttribute attribute =<br/>
(XmlSchemaAttribute)enumerator.Value;<br/>
<br/>
Console.WriteLine("Attribute: {0}", attribute.Name);<br/>
}<br/>
}<br/>
<br/>
// Get the sequence particle of the complex type.<br/>
XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;<br/>
<br/>
// Iterate over each XmlSchemaElement in the Items collection.<br/>
if(sequence != null)<br/>
foreach (XmlSchemaElement childElement in sequence.Items)<br/>
{<br/>
if(childElement.ElementSchemaType.BaseXmlSchemaType.DerivedBy == XmlSchemaDerivationMethod.Empty){<br/>
Console.WriteLine("Element: {0}", childElement.SchemaTypeName.Name);<br/>
Console.WriteLine("Element: {0}", childElement.Name);<br/>
}<br/>
}<br/>
}<br/>
}<br/>
}<br/>
static void ValidationCallback(object sender, ValidationEventArgs args)<br/>
{<br/>
if (args.Severity == XmlSeverityType.Warning)<br/>
Console.Write("WARNING: ");<br/>
else if (args.Severity == XmlSeverityType.Error)<br/>
Console.Write("ERROR: ");<br/>
<br/>
Console.WriteLine(args.Message);<br/>
}<br/>
}[/code]
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.
i would find only the properties of the element but the code print all the derived and not derived properties.<br/>
<br/>
for ex if i have:<br/>
<br/>
<xs:element substitutionGroup="ifc:IfcControl" name="IfcActionRequest" nillable="true" type="ifc:IfcActionRequest <br/>
</xs:element><br/>
<xs:complexType name="IfcActionRequest <br/>
<xs:complexContent><br/>
<xs:extension base="ifc:IfcControl <br/>
<xs:sequence><br/>
<xs:element name="RequestID" type="ifc:IfcIdentifier <br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:extension><br/>
</xs:complexContent><br/>
</xs:complexType><br/>
and<br/>
<br/>
<xs:element substitutionGroup="ifc:IfcObject" name="IfcControl" nillable="true" type="ifc:IfcControl" abstract="true <br/>
</xs:element><br/>
<xs:complexType name="IfcControl" abstract="true <br/>
<xs:complexContent><br/>
<xs:extension base="ifc:IfcObject <br/>
<xs:sequence><br/>
<xs:element name="ObjID" type="ifc:xxx <br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:extension><br/>
</xs:complexContent><br/>
</xs:complexType><br/>
<br/>
and<br/>
it print RequestId and ObjID and i dont wont ObjId.<br/>
Thanks.
View the full article
<pre>using System;<br/>
using System.Collections;<br/>
using System.Xml;<br/>
using System.Xml.Schema;<br/>
<br/>
class XmlSchemaTraverseExample<br/>
{<br/>
static void Main()<br/>
{<br/>
// Add the customer schema to a new XmlSchemaSet and compile it.<br/>
// Any schema validation warnings and errors encountered reading or <br/>
// compiling the schema are handled by the ValidationEventHandler delegate.<br/>
XmlSchemaSet schemaSet = new XmlSchemaSet();<br/>
//schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);<br/>
schemaSet.Add(null, "c:\IFC2X3.xsd");<br/>
schemaSet.Compile();<br/>
<br/>
// Retrieve the compiled XmlSchema object from the XmlSchemaSet<br/>
// by iterating over the Schemas property.<br/>
XmlSchema customerSchema = null;<br/>
foreach (XmlSchema schema in schemaSet.Schemas())<br/>
{<br/>
customerSchema = schema;<br/>
<br/>
<br/>
// Iterate over each XmlSchemaElement in the Values collection<br/>
// of the Elements property.<br/>
foreach (XmlSchemaElement element in customerSchema.Elements.Values)<br/>
{<br/>
<br/>
Console.WriteLine("Element: {0}", element.Name);<br/>
// Get the complex type of the Customer element.<br/>
XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;<br/>
<br/>
<br/>
Console.WriteLine("Base: {0}",element.SubstitutionGroup.Name);<br/>
// If the complex type has any attributes, get an enumerator <br/>
// and write each attribute name to the console.<br/>
if (complexType.AttributeUses.Count > 0)<br/>
{<br/>
IDictionaryEnumerator enumerator =<br/>
complexType.AttributeUses.GetEnumerator();<br/>
<br/>
while (enumerator.MoveNext())<br/>
{<br/>
XmlSchemaAttribute attribute =<br/>
(XmlSchemaAttribute)enumerator.Value;<br/>
<br/>
Console.WriteLine("Attribute: {0}", attribute.Name);<br/>
}<br/>
}<br/>
<br/>
// Get the sequence particle of the complex type.<br/>
XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;<br/>
<br/>
// Iterate over each XmlSchemaElement in the Items collection.<br/>
if(sequence != null)<br/>
foreach (XmlSchemaElement childElement in sequence.Items)<br/>
{<br/>
if(childElement.ElementSchemaType.BaseXmlSchemaType.DerivedBy == XmlSchemaDerivationMethod.Empty){<br/>
Console.WriteLine("Element: {0}", childElement.SchemaTypeName.Name);<br/>
Console.WriteLine("Element: {0}", childElement.Name);<br/>
}<br/>
}<br/>
}<br/>
}<br/>
}<br/>
static void ValidationCallback(object sender, ValidationEventArgs args)<br/>
{<br/>
if (args.Severity == XmlSeverityType.Warning)<br/>
Console.Write("WARNING: ");<br/>
else if (args.Severity == XmlSeverityType.Error)<br/>
Console.Write("ERROR: ");<br/>
<br/>
Console.WriteLine(args.Message);<br/>
}<br/>
}[/code]
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.
i would find only the properties of the element but the code print all the derived and not derived properties.<br/>
<br/>
for ex if i have:<br/>
<br/>
<xs:element substitutionGroup="ifc:IfcControl" name="IfcActionRequest" nillable="true" type="ifc:IfcActionRequest <br/>
</xs:element><br/>
<xs:complexType name="IfcActionRequest <br/>
<xs:complexContent><br/>
<xs:extension base="ifc:IfcControl <br/>
<xs:sequence><br/>
<xs:element name="RequestID" type="ifc:IfcIdentifier <br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:extension><br/>
</xs:complexContent><br/>
</xs:complexType><br/>
and<br/>
<br/>
<xs:element substitutionGroup="ifc:IfcObject" name="IfcControl" nillable="true" type="ifc:IfcControl" abstract="true <br/>
</xs:element><br/>
<xs:complexType name="IfcControl" abstract="true <br/>
<xs:complexContent><br/>
<xs:extension base="ifc:IfcObject <br/>
<xs:sequence><br/>
<xs:element name="ObjID" type="ifc:xxx <br/>
</xs:element><br/>
</xs:sequence><br/>
</xs:extension><br/>
</xs:complexContent><br/>
</xs:complexType><br/>
<br/>
and<br/>
it print RequestId and ObjID and i dont wont ObjId.<br/>
Thanks.
View the full article