Click here to Skip to main content
14,209,828 members
Click here to Skip to main content
Project
Posted 11 Jun 2019

Stats

2K views
2 bookmarked

C# Xml Any Object

,
Rate this:
3.08 (5 votes)
Please Sign up or sign in to vote.
3.08 (5 votes)
11 Jun 2019     MIT    
This class offers a Serialization or Deserialization of any xml sequence, using recursive algorithm concept; this feature is able to transform a xml string to XmlAnyObject object or XmlAnyObject object to xml string.

This class offers a Serialization or Deserialization of any xml sequence at compile time, using recursively algorithm concept; this feature is able to transform a xml string to XmlAnyObject object or XmlAnyObject object to xml string. Follow this example; I have one XML sequence like this:

<?xml version='1.0' encoding='UTF-8'?>
<Company att='teste'>
    <First>teste 1</First>
    <Second>teste 2</Second>
    <Third vvv='hello'>teste 3</Third>
    <FirstVarious>other test 1</FirstVarious>
</Company>
<Company>
    <First>novo teste 1</First>
    <Second bi='ttt'>novo teste 2</Second>
    <Third>novo teste 3</Third>
    <SecondVarious></SecondVarious>
    <ThirdVarious>other test 2</ThirdVarious>
</Company>

If do you want to consume this Xml above or multiples Xml without write C# Data Transfer Object for each Xml, use XmlAnyObject , with a simple line:

string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
               <Company att=""teste"">
                   <First>teste 1</First>
                   <Second>teste 2</Second>
                   <Third vvv=""hello"">teste 3</Third>
                   <FirstVarious>other test 1</FirstVarious>
               </Company>
               <Company>
                   <First>novo teste 1</First>
                   <Second bi=""ttt"">novo teste 2</Second>
                   <Third>novo teste 3</Third>
                   <SecondVarious></SecondVarious>
                   <ThirdVarious>other test 2</ThirdVarious>
               </Company>";
               
XmlAnyObject anyObject = XmlAnyObject.Deserialize(xml);

From Visual Studio QuickWatch, the developer throw and navigate to object nodes generated with dynamic type behavior, with the vantage to be executed at compile time: From: https://github.com/antonio-leonardo/XmlAnyObject


License

View MIT license

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

AntonioLeonardo
Architect teeWe
Brazil Brazil
+14 years of experience in Information Technology, with a background in Software Architecture / Engineering focused on Microsoft Solutions; the entire Development experience is in UI / UX, Desktop and Web Development (both Front End and Back End) through JavaScript and C# languages along with the ability to planning, configure and manage network infrastructure environments in any Windows ecosystem; Then, I gained the technical profile of "Solution Architect", capable of working on critical mission projects on the Microsoft platform, providing aspects in all layers involved: Operating system, database, Web servers, configuration of domain controllers, Integrated SharePoint Services, Server-side development in C # and client-side in HTML5, CSS3 and JavaScript (JQuery) to the client-side interface, along with administration, maintenance and security plans.

Comments and Discussions

 
QuestionTo become an article Pin
BillWoodruff12-Jun-19 16:34
mveBillWoodruff12-Jun-19 16:34 
QuestionWhy not LINQ to XML Pin
Sacha Barber11-Jun-19 22:24
mvaSacha Barber11-Jun-19 22:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190617.3 | Last Updated 11 Jun 2019
Article Copyright 2019 by AntonioLeonardo
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid