xmlns attribute???

Discussion in 'ASP .Net' started by John, Mar 4, 2008.

  1. John

    John Guest

    HI,

    I have a xml document containing a xmlns attribute.

    xmlns="urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list">

    I am using C# and statement xmlDoc.SelectNodes("//list") returns me nothing.

    However, if I remove that attribute, this C# statement works.

    Please help me understand this attribute.

    Thanks.
     
    John, Mar 4, 2008
    #1
    1. Advertising

  2. "John" <> wrote in message
    news:D...
    > HI,
    >
    > I have a xml document containing a xmlns attribute.
    >
    > xmlns="urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list">
    >
    > I am using C# and statement xmlDoc.SelectNodes("//list") returns me

    nothing.
    >
    > However, if I remove that attribute, this C# statement works.
    >
    > Please help me understand this attribute.
    >




    You need to use the XmlNamespaceManager

    XmlNamespaceManager nm = new XmlNamespaceManager(xmlDoc.NameTable);

    nm.AddNamespace("a",
    "urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list");

    XmlNodeList nl = xmlDoc.SelectNodes("//a:list", nm);




    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Mar 4, 2008
    #2
    1. Advertising

  3. John

    John Guest

    Thank you very much.

    "Anthony Jones" wrote:

    >
    > "John" <> wrote in message
    > news:D...
    > > HI,
    > >
    > > I have a xml document containing a xmlns attribute.
    > >
    > > xmlns="urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list">
    > >
    > > I am using C# and statement xmlDoc.SelectNodes("//list") returns me

    > nothing.
    > >
    > > However, if I remove that attribute, this C# statement works.
    > >
    > > Please help me understand this attribute.
    > >

    >
    >
    >
    > You need to use the XmlNamespaceManager
    >
    > XmlNamespaceManager nm = new XmlNamespaceManager(xmlDoc.NameTable);
    >
    > nm.AddNamespace("a",
    > "urn:schemas-microsoft-com:pAG:MyList-application-block:v2:list");
    >
    > XmlNodeList nl = xmlDoc.SelectNodes("//a:list", nm);
    >
    >
    >
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET
    >
    >
    >
     
    John, Mar 5, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john1001

    Unrecognized attribute 'xmlns'.

    john1001, Oct 14, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    6,132
    Juan T. Llibre
    Oct 15, 2005
  2. kai
    Replies:
    7
    Views:
    2,289
    Steven Cheng[MSFT]
    Nov 21, 2005
  3. =?Utf-8?B?RXdhbiBGYWlyd2VhdGhlcg==?=

    Need to remove blank XMLNS attribute from xmldocument

    =?Utf-8?B?RXdhbiBGYWlyd2VhdGhlcg==?=, Apr 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,136
    =?Utf-8?B?RXdhbiBGYWlyd2VhdGhlcg==?=
    Apr 14, 2006
  4. Replies:
    0
    Views:
    1,413
  5. afshar
    Replies:
    3
    Views:
    24,776
    aljar
    May 19, 2010
Loading...

Share This Page