Example Of Parsing an xml into the object tree:

consider an xml:
<RootElement>
  <ChildElement>Value</ChildElement>
</Rootelement>

  RootElementoxm parsed = new RootElementoxm(xmlstring);

This will parse the xml into the object tree.
Always try to parse from the root element into root object, which is the only class with a string in the parameter constructor, but if not use this code snippet to parse from any XML to any class with the same name:

<OneOfYourGeneratedTypes>
   <Property>Value</Property>
</OneOfYourGeneratedTypes>

Can be parsed using this code snippet (assuming you load the XML from test file)

var x = new OneOfYourGeneratedTypes();
var xml = File.ReadAllText("YourXmlFile.xml");
x.MapToPackage(xml);

With Databinding enabled and full properties:

<xs:attribute name="Additional" type="xs:string" use="optional" />

Will generate

        private string _Additional;
        [OxmXmlAttribute("Additional")]
        public string Additional
        {
            get
            {
                return _Additional;
            }
 
            set
            {
                _Additional = value;
                OnPropertyChanged("Additional");
            }
        }

With custom lists, this:

<xs:element maxOccurs="unbounded" name="Parameter">

Will generate:

        private System.Collections.Generic.List<Parameteroxm> _Parameter;
        public System.Collections.Generic.List<Parameteroxm> Parameter
        {
            get
            {
                if (_Parameter == null)
                  _Parameter = new System.Collections.Generic.List<Parameteroxm>();
                return _Parameter;
            }
 
            set
            {
                _Parameter = value;
                OnPropertyChanged("Parameter");
            }
        }

Last edited Feb 22, 2013 at 6:39 AM by shani78, version 4

Comments

No comments yet.