Click here to Skip to main content
15,664,182 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in programming and learning new things following online tutorials and you guys. Nowadays! I am reading and learning about LINQ to XML, I have XML followings that have some element/attribute, how to write a query that retrieves data in the following order.

Order Id =

Order Person details:
Name = Combine firstname and lastname
Phone number details:
xxxxxxxxx (Mobile)
yyyyyyyy (Fax)

Shiping details:

Items details:
Item # 1
Note (if it exist)

Item # 2
Note (if it exist)

What I have tried:

<shiporder orderid="889923" xmlns:xsi="">
        <name>Irfan Nazir</name>
        <address>Langgt 23</address>
        <city>4000 Stavanger</city>
            <title>Empire Burlesque</title>
            <note>Special Edition</note>
            <title>Hide your heart</title>
Updated 2-Apr-21 7:30am

1 solution

I think you're better off using serialization. The topic of serialization is honestly too big to cover in a QA answer, but it's easy to find info on the google machine.

There's a lot of prep to use it correctly, but once you've got your entities setup correctly, it comes down to a single line of code to read your xml file.

There are no shortcuts to learning how to do things when you're writing code.

For what it's worth, there are a number of articles posted on CodeProject regarding XML serialization. You should search the site and find an article that explains it in a way you understand.
Share this answer
Adi Mirza 2-Apr-21 6:44am    
thank you very much for a tip #realJSOP I will look for it
Garth J Lancaster 3-Apr-21 20:36pm    
as realJSOP said ... look, you COULD write LINQ/XML, but then you're still stuck with getting the three different types of result from the result of that - which could be just as painful .. if you really need the LINQ having looked at deserialisation, you would be better off with three queries, assuming the shipping order has only one orderperson, shipto & then the multiple items can be a collection on their own

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900