Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Namespace headache

Question posted by: egholm@gmail.com (Guest) on June 27th, 2008 07:20 PM
I'm using the following XML:

---------------------------------------------------------------------------*--------------
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Url="_catalogs/masterpage" Path="PageLayouts">
<File Url="List.aspx" Type="GhostableInLibrary">
</Module>
</Elements>
---------------------------------------------------------------------------*---------------

When I query the xml with the code below I get no results.
But if I remove the namespace "xmlns="http://schemas.microsoft.com/
sharepoint/"" from xml above everything works fine. I want to keep the
namespace in the xml. What do I do wrong?

XElement pagelayouts = XElement.Load("ProvisionedFiles.xml");
var query = from c in pagelayouts.Descendants("File") select c;

foreach(var q in query)
{
//Something
}

egholm@gmail.com's Avatar
egholm@gmail.com
Guest
n/a Posts
June 27th, 2008
07:20 PM
#2

Re: Namespace headache
Found a solution. This will do the trick:

XNamespace ns = "http://schemas.microsoft.com/sharepoint/";
XElement pagelayouts = XElement.Load("ProvisionedFiles.xml");
var query = from c in pagelayouts.Descendants(ns + "File") select c;

 
Not the answer you were looking for? Post your question . . .
190,077 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors