Using ORM to manipulate an XML document, an object is not too easy to handle. Fuck off! XmlDocument, XmlNode, xml*** ...

Source: Internet
Author: User

There is no such feeling, one involves the operation of the XML document Baidu again. It's not ! Often! Bother!. various types, various methods, let alone to find a node more laborious. Originally wanted to write an XML operation tool method, wrote two lines one think since the XML document is regular, if the abstract into a tree-like structure of the class , find the node is not can use lambda, create the modification is the Operation class, it is not easy to fly! Say dry, after two days of polishing, finally is done. system default XML file-related operations I'm not going to throw up the groove, let's see how it flies.

   Design ideas:

It's a lot of writing, simply to divide the XML tags into two categories:Xmlchildtag and xmlbasetag base tags. A child tag can have a child tag list and a list of underlying tags , so a child tag can represent the root node of an XML file. Then a xmlfile file class implements functions such as XmlDocument to Xmltag tag classes . Speaking of space:

  1. The model is defined as follows. Note that Xmltag is an abstract class.

  2. File model XMLFile (too long, look at the basic definition first.) The project is on GitHub and there are links underneath. )

Internal implementation of what I do not say, interested students go to GitHub to see the sixants.xmlfile Project, the comments should be very detailed (for crooked nuts I also wrote an English note ...) )。

   go to the chase, how to fly:

  1. Creating an XML file

  Results

  2. Read the XML file

  Results

3. Modify the Content

  Results

4. Fast acquisition of nodes (one of the key flying Steps) (to show a few different methods to look at the longer, the actual completion of a search and modification will be two or three lines of code to fix.) )

before execution: after execution:

After two days of tossing, it was almost the same. The core idea is to match the label to the model class of the tree structure, and realize the transformation between the model class and the XmlNode. Maps the operations of a class to XmlNode operations.

Although the code is not much, but in order to be reasonable and easy to use, the model changed two or three times, the model is actually free to operate, in order to quickly and efficiently, plus the relevant fast access method. I...... It's probably ... For world Peace ...

  need to see the source code or to improve the students see here :https://github.com/631320085/SixAnts.XmlFile

  Students who want to use can also search for "sixants.xmlfile" or execute commands directly from NuGet: Install-package sixants.xmlfile

In addition: NuGet Post dll Comments are gone, there is time to study how to add, read it almost know how to use it. Unreasonable operation will throw an exception (exception does not have English, too lazy to get) does not guarantee no bug ah, just write well, continuous improvement in ...

Using ORM to manipulate an XML document, an object is not too easy to handle. Fuck off! XmlDocument, XmlNode, xml*** ...

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.