Introduction
Generally, we use LINQ to XML while reading data from XML. LINQ to XML works perfectly with XML normal data without namespace. But sometime we get XML data with namespace and in that scenario it won’t work perfectly. In order to resolve problem, we need to create XNamespace object and bind it LINQ to XML. Let’s see how we can achieve.
The following is the XML data from where we will read data. In below XML data you will find namespace is used (xmlns).
Generally, we use LINQ to XML while reading data from XML. LINQ to XML works perfectly with XML normal data without namespace. But sometime we get XML data with namespace and in that scenario it won’t work perfectly. In order to resolve problem, we need to create XNamespace object and bind it LINQ to XML. Let’s see how we can achieve.
The following is the XML data from where we will read data. In below XML data you will find namespace is used (xmlns).
- <?xml version="1.0" encoding="iso-8859-1"?>
- <league xmlns="http://feed.elasticstats.com/schema/basketball/schedule-v2.0.xsd">
- <daily-schedule date="2014-04-13">
- <games>
- <game id="53a41428-d8f7-4020-97cc-13792e6994eb" status="closed" scheduled="1">
- <venue name="Bankers Life Fieldhouse"/>
- <home name="Indiana Pacers" alias="IND">
- </home>
- <away name="Oklahoma City Thunder">
- </away>
- </game>
- </games>
- </daily-schedule>
- </league>

Join the conversation! Your thoughts help the community grow.