+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 32

Thread: cegonsoft.org | LINQ to XML in C#.NET

  1. #1

    Default cegonsoft.org | LINQ to XML in C#.NET

    Consider that we want to create the following XML Document:

    <?xml version="1.0"? encoding="utf-8">
    <!–Xml Document–>
    <catalog>
    <book id="bk001">
    <title>Book Title</title>
    </book>
    </catalog>
    </xml>

    Here is how we create the same XML document using Linq to Xml classes available in the System.Xml.Linq namespace:

    XDocument doc =
    new XDocument(
    new XDeclaration("1.0", Encoding.UTF8.HeaderName, String.Empty),
    new XComment("Xml Document"),
    newXElement("catalog",
    new XElement("book",
    newXAttribute("id", "bk001"),
    newXElement("title", "Book Title")
    )
    )
    );
    doc.Save("sampleLinq.xml");


    For more information, visit Cegonsoft

  2. #2

    Default

    XML (Extensible markup language) is all about describing data. Below is a XML which
    describes invoice data.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <invoice>
    <productname>Shoes</productname>
    <qty>12</qty>
    <totalcost>100</totalcost>
    <discount>10</discount>
    </invoice>
    An XML tag is not something predefined but it is something you have to define according
    to your needs. For instance in the above example of invoice all tags are defined according
    to business needs. The XML document is self explanatory, any one can easily understand
    looking at the XML data what exactly it means.

    Cegonsoft

  3. #3

    Default

    We can generate hierarchical object graph in our memory though LINQ. To be more realistic we can bring data from relational database. So if we consider database and use LINQ to SQL to bring all the Customers and their Orders and Order Details the query would look like,





    //LINQ to SQL way to get data from database

    var q = from c in db.Customers

    select new

    {

    CId = c.CustomerID,

    Orders = from o in c.Orders

    select new

    {

    OID = o.OrderID,

    Qty = from od in o.Order_Details

    select new { Qty = od.Quantity }

    }

    };







    So what I am trying to do here is that, I am trying to fetch CustomerId from Customers table and OrderId from Orders table and Quantity from Order Details table. It is bringing 3 level deep data for me and storing it to memory.



    By using XElement and XAttribute I will create a single XML stream. Which will look like,



    <?xml version="1.0" encoding="utf-8"?>

    <customers>

    <customer id="ALFKI" country="Germany" contactName="Maria Anders" contactTitle="Sales Representative">

    <Orders id="10643" date="1997-08-25T00:00:00">

    <items>

    <item price="45.6000" quantity="15" />

    <item price="18.0000" quantity="21" />

    <item price="12.0000" quantity="2" />

    </items>

    </Orders>

    <Orders id="10692" date="1997-10-03T00:00:00">

    <items>

    <item price="43.9000" quantity="20" />

    </items>

    </Orders>



    …….



    To achieve this I have to write a very simple query like syntax based on the query I have written earlier,



    var query = new XElement("customers",

    from c in db.Customers

    select

    new XElement("customer",

    new XAttribute("id", c.CustomerID),

    new XAttribute("country", c.Country),

    new XAttribute("contactName", c.ContactName),

    new XAttribute("contactTitle", c.ContactTitle),



    from o in c.Orders

    select new XElement("Orders",

    new XAttribute("id", o.OrderID),

    new XAttribute("date", o.OrderDate),

    new XElement("items",



    from od in o.Order_Details

    select new XElement("item",

    new XAttribute("price", od.UnitPrice),

    new XAttribute("quantity", od.Quantity))))));


    Many good and new technology training in framework 4.0 in dotnet by cegonsoft


    It looks complex because it is one liner but actually it is very simple. This will give you the exact XML output mentioned earlier.

  4. #4

    Default

    Hi,
    While having nice reviews, Cegonsoft is the best IT training centre who makes freshers to learn and understand various technologies quickly and easily and also place them in various multinational companies .They have Experienced and Intelligent Tech Consultants who puts a lot of effort and hard work to make all these possible. The HR team has also doing very nice work to provide Soft Skills and guide students according to the Corporate Standard requirements and as a result most of the students are getting placement right after training.

    Cegonsoft

  5. #5

    Default

    Using the classes from the System.Xml.Linq namespace and the features available in .NET 3.5, constructing an XML document is very easy and very readable.
    public static void CreateEmployees()
    {
    XDocument doc = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
    new XComment("A sample xml file"),
    new XElement("employees",
    new XElement("employee",
    new XAttribute("id", 1),
    new XAttribute("salaried", "false"),
    new XElement("name", "Gustavo Achong"),
    new XElement("hire_date", "7/31/1996")),
    new XElement("employee",
    new XAttribute("id", 3),
    new XAttribute("salaried", "true"),
    new XElement("name", "Kim Abercrombie"),
    new XElement("hire_date", "12/12/1997")),
    new XElement("employee",
    new XAttribute("id", 8),
    new XAttribute("salaried", "false"),
    new XElement("name", "Carla Adams"),
    new XElement("hire_date", "2/6/1998")),
    new XElement("employee",
    new XAttribute("id", 9),
    new XAttribute("salaried", "false"),
    new XElement("name", "Jay Adams"),
    new XElement("hire_date", "2/6/1998"))
    )
    );
    }

    cegonsoft

  6. #6

    Default

    Cegonsoft provides the very good training in the technology wise.They provide the technology training on the basis of the industry standard.So that the cegonsoft trained peoples get the good placement and also they get the the good knowledge in their desired field.
    In cegonsoft they provide the soft skill training.In this training the HR mold the students based on the industry standard.
    They provide the good placement opportunity also so that the students in the cegonsoft get the opportunity to attend the many companies..
    Cegonsoft

  7. #7
    Emerald Star member madhusundar is on a distinguished road
    Join Date
    Sep 2011
    Posts
    104

    Default

    The .NET framework created by Microsoft is a software development platform that focuses on rapid application development,
    platform independence and network transparency.
    .NET is Microsoft's strategic initiative for server and desktop development for the next decade.
    According to Microsoft, .NET includes many technologies that are designed to facilitate rapid development
    of Internet and Intranet applications. .NET-connected solutions aim to enable businesses integrate their systems
    more rapidly and in a more agile manner and help them realize the promise of information anytime, anywhere, on any device.


    ASP.NET is a server side scripting technology that enables scripts (embedded in web pages) to be executed by an Internet server.

    ASP.NET is a Microsoft Technology
    ASP stands for Active Server Pages
    ASP.NET is a program that runs inside IIS
    IIS (Internet Information Services) is Microsoft's Internet server
    IIS comes as a free component with Windows servers
    IIS is also a part of Windows 2000 and XP Professional


    The .NET Framework is the infrastructure for the Microsoft .NET platform.

    The .NET Framework is an environment for building, deploying, and running Web applications and Web Services.


    TRAINING IN CEGONSOFT:
    CEGONSOFT is one of the country's fastest growing Information Technology Solution Company. CEGONSOFT has established itself with three independent successful divisions.

    Software Training
    Software Development
    HR Consultancy
    Providing International Certifications after the course and job assistance will be done through the HR.

    Cegonsoft
    Last edited by madhusundar; 10-01-2011 at 10:29 AM.

  8. #8

    Default

    Usage of xml is an advantage in asp.net
    Cegonsoft

  9. #9

    Default

    Using XML with Microsoft. NET Framework version 2.0 and below is a difficult task. API follows the W3C DOM, and is centered on the documents. It all starts with the document that you can not create elements without having a document, and even a fragment of an XML document.

    In the latest version of the Framework. NET, however, this changed. XML is now focused on the item. With features such as object initialization and anonymous types, it is very easy to create XML. Add to that the features of LINQ s', and now we have a very easy tool to use and powerful XML.

    In this article I will explore some of the features available in. NET Framework version 3.5 related to XML and LINQ. This is obviously not an exhaustive discussion on the subject is just an orientation and a springboard for further learning and exploration.

    cegonsoft

  10. #10
    Emerald Star member madhusundar is on a distinguished road
    Join Date
    Sep 2011
    Posts
    104

    Default C# and dot net training in CEGONSOFT

    C# is Microsoft's new programming language for the .NET platform.
    It combines some of the best features of modern programming languages such as Java, C++ or Visual Basic.
    C# is an object-oriented language with single inheritance but multiple interfaces per class.
    It supports component-based programming by properties (smart fields), events and delegates (enhanced function pointers).
    C# is fully interoperable with other .NET languages such as VB.NET, Eiffel.NET or Oberon.NET.


    CEGONSOFT is one of the country's fastest growing Information Technology Solution Company. CEGONSOFT has established itself with three independent successful divisions.

    Software Training
    Software Development
    HR Consultancy
    Providing International Certifications after the course and job assistance will be done through the HR.

+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts