How to read namespace based xml using Linq

In this post,I will show you how to read xml with namespace.For this demo,I will use following xml


<?xml version="1.0" encoding="utf-8" ?>
<accounts xmlns="urn:account">


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace XLinq
    class Program
        static void Main(string[] args)
            var doc = XDocument.Load("accounts.xml");
            var query = from x in doc.Descendants("{urn:account}account")
                        select x;
            foreach (var item in query)

No comments:

Post a Comment