return true if a Element is a Choice from XmlSchemaComplexType - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

return true if a Element is a Choice from XmlSchemaComplexType

Demo Code


using System.Xml.Schema;
using System.Xml;
using System.Text;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections;
using System;//from   w ww.  ja v a 2s  .  com

public class Main{
        /// <summary>
        /// return true if a Element is a Choice
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static bool IsChoiceType(XmlSchemaComplexType complexType)
        {

            if (complexType != null)
            {
                #region choice
                // check if it is e choice
                XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice;
                if (choice != null)
                {
                    return true;
                }
                #endregion
            }
     
            return false;
        }
        /// <summary>
        /// return true if a Element is a Choice
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static bool IsChoiceType(XmlSchemaElement element)
        {
            if (element.ElementSchemaType is XmlSchemaComplexType)
            {
                XmlSchemaComplexType ct = element.ElementSchemaType as XmlSchemaComplexType;

                if (ct != null)
                {
                    #region choice
                    // check if it is e choice
                    XmlSchemaChoice choice = ct.ContentTypeParticle as XmlSchemaChoice;
                    if (choice != null)
                    {
                        return true;
                    }
                    #endregion
                }
            }

            return false;
        }
}

Related Tutorials