Click here to Skip to main content
15,904,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<validationrule>
  <fieldname>
    <entitytype>02</entitytype>
    <name>PANRangeLow</name>
    <isrequired>True</isrequired>
    <isrequirederrormessage>PAN Range Low is required</isrequirederrormessage>
    <datatype>Number</datatype>
    <datatypeerrormessage>PAN Range Low must be numeric</datatypeerrormessage>
</fieldname>
  <fieldname>
    <entitytype>02</entitytype>
    <name>PANRangeHigh</name>
    <isrequired>True</isrequired>
    <isrequirederrormessage>PAN Range High is required</isrequirederrormessage>
    <datatype>Number</datatype>
    <datatypeerrormessage>PAN Range High must be numeric</datatypeerrormessage>
  </fieldname>
</validationrule>
Posted

XMLSerializer with XMLReaderSettings should give you a solution.
Try this tip - XML Serialization and Deserialization[^].
 
Share this answer
 
You can try this. I found the solution from here http://stackoverflow.com/questions/4203540/generate-c-sharp-class-from-xml[^]

C#
/// <remarks />
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class validationrule
    {

        private validationruleFieldname[] fieldnameField;

        /// <remarks />
        [System.Xml.Serialization.XmlElementAttribute("fieldname")]
        public validationruleFieldname[] fieldname
        {
            get
            {
                return this.fieldnameField;
            }
            set
            {
                this.fieldnameField = value;
            }
        }
    }

    /// <remarks />
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    public partial class validationruleFieldname
    {

        private byte entitytypeField;

        private string nameField;

        private string isrequiredField;

        private string isrequirederrormessageField;

        private string datatypeField;

        private string datatypeerrormessageField;

        /// <remarks />
        public byte entitytype
        {
            get
            {
                return this.entitytypeField;
            }
            set
            {
                this.entitytypeField = value;
            }
        }

        /// <remarks />
        public string name
        {
            get
            {
                return this.nameField;
            }
            set
            {
                this.nameField = value;
            }
        }

        /// <remarks />
        public string isrequired
        {
            get
            {
                return this.isrequiredField;
            }
            set
            {
                this.isrequiredField = value;
            }
        }

        /// <remarks />
        public string isrequirederrormessage
        {
            get
            {
                return this.isrequirederrormessageField;
            }
            set
            {
                this.isrequirederrormessageField = value;
            }
        }

        /// <remarks />
        public string datatype
        {
            get
            {
                return this.datatypeField;
            }
            set
            {
                this.datatypeField = value;
            }
        }

        /// <remarks />
        public string datatypeerrormessage
        {
            get
            {
                return this.datatypeerrormessageField;
            }
            set
            {
                this.datatypeerrormessageField = value;
            }
        }
    }
 
Share this answer
 
Should use XMLSerializer class .

You can try something like

[Serializable()]
public class FieldName
{
    [System.Xml.Serialization.XmlElement("EntityType")]
    public string EntityType { get; set; }

    [System.Xml.Serialization.XmlElement("Name")]
    public string Name { get; set; }

    ...
}

[Serializable()]
[System.Xml.Serialization.XmlRoot("validationrule")]
public class validationrules
{
    [XmlArray("FieldName")]
    [XmlArrayItem("FieldName", typeof(FieldName))]
    public FieldName[] fieldNames { get; set; }
}

// the below code may be added into your deserialize method
validationrule rules= null;
string path = "xmlpath.xml";

XmlSerializer serializer = new XmlSerializer(typeof(validationrules));

using (XmlReader reader = XmlReader.Create(path))
    {
        rules =  serializer.Deserialize(reader) as validationrules;
    }


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900