7.7. Query for Elements in a Specific XML Namespace

Problem

You need to filter the contents of or find specific elements in an XML document that belong to a specific XML namespace.

Solution

Define any appropriate namespaces, and then perform your query using any of the clauses available in System.Xml.Linq, ensuring that you specify the appropriate namespace to use.

How It Works

As with the .NET Framework itself, XML namespaces are used to separate elements into groups. Every XElement object in an XML tree contains an XName object, which in turn contains an XNamespace object. If you have XML that contains information from multiple sources or related to multiple entities, using namespaces provides an appropriate mechanism for dividing the information ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.