Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:01:04+00:00 2026-06-12T18:01:04+00:00

My Input <A xmlns=http://abc.com> <B>b</B> <C>c</C> </A> My Code XNamespace ns = XNamespace.Get(http://abc.com); var

  • 0

My Input

<A xmlns="http://abc.com"> 
    <B>"b"</B>
    <C>"c"</C>
    </A>

My Code

XNamespace ns = XNamespace.Get("http://abc.com");

var query= from node in doc.Descendants(ns+ "A") 
           select new
            (
                        B = (string)node.Element(ns+"B"),
                            C = (string)node.Element(ns+ "C")
             );

My Question

Do I have to add ns every time I am doing node.Element()? or is there any other way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:01:05+00:00Added an answer on June 12, 2026 at 6:01 pm

    Do I have to add ns every time I am doing node.Element()?

    Yes, basically. You’re looking for (say) an element with a local name of B and a namespace URI of “http://abc.com”.

    You could write your own extension method which matched any element with the right local name, but I’d advise against it. It would be something like:

    public IEnumerable<XElement> ElementsWithLocalName(this XContainer container,
        string localName)
    {
        return container.Elements().Where(x => x.Name.LocalName == localName);
    }
    
    public IEnumerable<XElement> ElementsWithLocalName<T>(
        this IEnumerable<T> source,
        string localName) where T : XContainer
    {
        return source.Elements().Where(x => x.Name.LocalName == localName);
    }
    

    This would make your code less reliable though – do you really want to match just any old name with the right local name?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code : <html xmlns=http://www.w3.org/1999/xhtml> <body style=height: 1336px> <input type=hidden id=loadingtime/>
I'm building a custom keyboard in android. My input.xml: <com.mykeyboard.MyKeyboardView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/keyboard android:layout_width=match_parent android:layout_height=wrap_content
I got a xml like below string input = @<g1:Person xmlns:g1=http://api.google.com/staticInfo/> <g1:Id>005008</g1:Id> <g1:Infolist> <g1:Info><g1:Title>a</g1:Title></g1:Info>
I have input xml of the form <content xml:lang=en xmlns:w=http://www.w.com/sch/W> <w:firstRowHeader>true</w:firstRowHeader> <w:firstColumnHeader>true</w:firstColumnHeader> <w:customTable> <w:tableContent>
managed to get my xsl working at http://www.xmlper.com/ (great tool good recommendation from other
My input xml would be like this with json namespaces.. <json:object xmlns:json=http://www.ibm.com/xmlns/prod/2009/jsonx xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <json:object
Input: <document xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance type=NOIA xsi:noNamespaceSchemaLocation=sample.xsd> <id>X17A</id> <companyName>Foo Bars</companyName> <p>Lorem ipsum dolor sit amet, consectetur
<UserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:toolkit=http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit xmlns:System_Windows_Controls_Primitives=clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Toolkit x:Class=SilverlightApplication5.MainPage Width=640 Height=480> <StackPanel x:Name=LayoutRoot Background=White> <TextBox x:Name=tbWidth TextWrapping=Wrap
If I run the following XSLT code: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output method=text/> <xsl:key name=kValueByVal
I have this login.xhtml JSF page: <?xml version=1.0?> <jsp:root version=2.0 xmlns:jsp=http://java.sun.com/JSP/Page xmlns:f=http://java.sun.com/jsf/core xmlns:h=http://java.sun.com/jsf/html> <jsp:directive.page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.