A verbose on part 3 of Liu Dongxia's Spring. NET Series Study Notes

Source: Internet
Author: User

Just like the question raised by his "waiting for nothing" on the fifth floor, there is a little problem with the code below,

XElement root = objects =  obj  root.Elements()  obj;

If you copy the code of Liu Dongxia, it will not be able to read the data. I think it should be a ray that Liu Dongxia intentionally buried.

According to his article, I practiced it again:

First, several classes are created, one Person class, one Man class, and one Woman class. There are three classes in total. xml documents will be created based on these three classes;

Person:

   Name { ;   Sex { ;   Eat(  : Console.WriteLine(.Name +  + person.Name + );  : Console.WriteLine(.Name +  + person.Name + ); : 

Man:

  Man( name, .Name =.Sex =

Woman:

  Woman( name, .Name =.Sex =

Next, we will create an xml document based on the above three classes (hand-written,

Object. xml:

         

Followed by the XmlFcatory class:

  IDictionary<, > objectDefine =  Dictionary<, > XmlFactory(  InstanceObjects(= = ns + = objects =  obj  root.Elements(name) ==>=> typeName = v.Attribute(=  GetObject( result = =

Finally, it is called at the entrance of the main program:

Program class:

  Main( =  XmlFactory(= ctx.GetObject() = = = ctx.GetObject() = = + + 

This is a complete practice, but the error is slightly modified.

The modified code is as follows:

  InstanceObjects(= = ns + = objects =  obj  root.Elements(name) ==> k.Attribute().Value,                v => typeName = v.Attribute(=

In this way, data can be normally read.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.