Note that there are some explanatory texts on larger screens.

plurals
  1. POThe Attribute of "ref" for XML Schema For C# Parse
    primarykey
    data
    text
    <p>Good day.</p> <p>I got a problem about the attribute of "ref" for my XSD file. My code :</p> <pre><code>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("http://www.w3.org/2001/XMLSchema", "recipe.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; // If the complex type has any attributes, get an enumerator // and write each attribute name to the console. if (complexType.AttributeUses.Count &gt; 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. foreach (XmlSchemaElement childElement in sequence.Items) { Console.WriteLine("Element: {0}, {1}, {2}", childElement.RefName, childElement.MinOccurs, childElement.MaxOccurs); } } } 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); } } </code></pre> <p>my XSD file</p> <pre><code>&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;xsd:element name="Recipe"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element ref="DocumentInfo" minOccurs="1" maxOccurs="1" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;!-- Element of DocumentInfo --&gt; &lt;xsd:element name="DocumentInfo"&gt; &lt;xsd:complexType&gt; &lt;xsd:attribute name="Name" type="xsd:string" /&gt; &lt;xsd:attribute name="Description" type="xsd:string" /&gt; &lt;xsd:attribute name="Creator" type="xsd:string" /&gt; &lt;xsd:attribute name="CreateTime" type="xsd:string" /&gt; &lt;xsd:attribute name="Revisor" type="xsd:string" /&gt; &lt;xsd:attribute name="ReviseTime" type="xsd:string" /&gt; &lt;xsd:attribute name="Version" type="xsd:string" /&gt; &lt;xsd:attribute name="Frozen" type="xsd:boolean" /&gt; &lt;xsd:attribute name="ASCSVersion" type="xsd:string" use="optional"/&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;/xsd:schema&gt; </code></pre> <p>Now when i got the output below:</p> <pre><code>Element: Recipe Element: http://www.w3.org/2001/XMLSchema:DocumentInfo, 1, 1 Element: http://www.w3.org/2001/XMLSchema:Prerequisite, 1, 1 Element: http://www.w3.org/2001/XMLSchema:Headers, 0, 1 Element: http://www.w3.org/2001/XMLSchema:Steps, 1, 1 </code></pre> <p>How to remove the prefix of "<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow noreferrer">http://www.w3.org/2001/XMLSchema</a>" ? I can only take use of the Attribute of "childElement.RefName", I can't find "childElement.Ref".</p> <p>DEV IDE: VS2005. .NET 2.0.</p> <p>Thanks in advance here.</p> <p>BR! Nano</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload