Namespace headache

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • egholm@gmail.com

    Namespace headache

    I'm using the following XML:

    ---------------------------------------------------------------------------­--------------
    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microso ft.com/sharepoint/">
    <Module Url="_catalogs/masterpage" Path="PageLayou ts">
    <File Url="List.aspx" Type="Ghostable InLibrary">
    </Module>
    </Elements>
    ---------------------------------------------------------------------------­---------------

    When I query the xml with the code below I get no results.
    But if I remove the namespace "xmlns="htt p://schemas.microso ft.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(" ProvisionedFile s.xml");
    var query = from c in pagelayouts.Des cendants("File" ) select c;

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

  • egholm@gmail.com

    #2
    Re: Namespace headache

    Found a solution. This will do the trick:

    XNamespace ns = "http://schemas.microso ft.com/sharepoint/";
    XElement pagelayouts = XElement.Load(" ProvisionedFile s.xml");
    var query = from c in pagelayouts.Des cendants(ns + "File") select c;

    Comment

    Working...