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 887975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:19:03+00:00 2026-05-15T13:19:03+00:00

So I want to access the child element in a structure that looks like

  • 0

So I want to access the child element in a structure that looks like this:

<asdf:foobar attr="value">
    <child>...</child>
</asdf:foobar>

I forget what the asdf is called, but it is what’s causing the problem. My normal method of traversing in XLinq doesn’t work:

xElem child = xDoc.Element("foobar");

Sets child to null because it claims there is no element foobar, and

xElem child = xDoc.Element("asdf:foobar");

Doesn’t work because the compiler whines about the semicolon.

All help is appreciated, and thanks in advance!

UPDATE:

I’ve been working on a reproduction of this as an example (since I can’t show you the actual code). My test code:

        Console.WriteLine("BEGIN TEST");

        const string MY_SCHEMA = "http://www.example.com/whatever";

        XElement xTest =
        new XElement("{" + MY_SCHEMA + "}base",
            new XAttribute("{" + XML_STANDARD + "}boofar", MY_SCHEMA),
            new XAttribute("attr1", "val"),
            new XElement("{" + MY_SCHEMA + "}asdf", "ghjkl")
        );

        result.Text = xTest.ToString();

        XElement xOps2 = xTest.Element(XName.Get("asdf", MY_SCHEMA));
        XElement xSubOps2;

        if (xOps2 == null)
        {
            MessageBox.Show("Failure.");
        }
        else
        {
            xSubOps2 = xOps2.Element(XName.Get("asdf", MY_SCHEMA));
            MessageBox.Show(xSubOps2.ToString());
        }

        Console.WriteLine("END TEST");

        MessageBox.Show("END TEST");

This displays the XML that I want:

<boofar:base xmlns:boofar="http://www.example.com/whatever" attr1="val">
  <boofar:asdf>ghjkl</boofar:asdf>
</boofar:base>

And everything is working great. Thanks all!

  • 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-05-15T13:19:04+00:00Added an answer on May 15, 2026 at 1:19 pm

    Unfortunately the implicit conversion from string to XName does not parse out the namespace. You need to do this:

    XName.Get("foobar", "asdf");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse some XML that looks like this: <node> This is <child>
I want to access an element using a DOM hierarchy Node structure, through its
I have a dictionary list and I want to access the 2nd child element
Hi this is my code i want to access the KEY_ID that i put
I want to access java script's return value , which in is in a
I want to access text-shadow property just like we access padding property. Means ,
i had an global structure like this:- struct MachineList { BSTR AccountId; BSTR MachineId;
I have a grid control. And I want to access gridview child control from
Im familiar with accessing parent windows like this: window.parent.document.getElementById(ad_nr) But what if I want
Using Ember.CollectionView I want to access and manipulate the DOM element which is being

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.