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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:59:58+00:00 2026-06-03T10:59:58+00:00

I have an XElement which it’s output is <Email>address@email.com</Email> . Base on some criteria

  • 0

I have an XElement which it’s output is

<Email>address@email.com</Email>

. Base on some criteria I will possibly need to remove the email address and set it to null. I know I can yous set element.Value =””; but that will not do what I want. I want to modify it so the output will become:

<Email xsi:nil=\"true\" />

I don’t want to create a brand new node because this is a referenced node within a document. and i want to keep the node where it is within the document.
I tried

emailItem.Add(new XAttribute("xsi:nil", "true"));

but I received the following exception

The ‘:’ character, hexadecimal value 0x3A, cannot be included in a
name.
The following changes create the node almost correctly:

XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";                                    
emailItem.Add(new XAttribute(xsi + "nil", true));
emailItem.Value =""; //How do I set to Null?

I end up with <Email xsi:nil="true"></Email> instead <Email xsi:nil="true"/>

  • 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-03T11:00:10+00:00Added an answer on June 3, 2026 at 11:00 am

    Yes, you need to specify the XName differently; you can’t just create an XName in a namespace like that.

    I suspect you want this:

    XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
    emailItem.Document.Root.Add(new XAttribute(XNamespace.Xmlns + "xsi",
                                xsi.ToString()));
    emailItem.Add(new XAttribute(xsi + "nil", true);
    

    Complete example:

    using System;
    using System.Xml.Linq;
    
    class Test
    {
        static void Main()
        {
            XDocument doc = new XDocument(new XElement("root"));
            XElement element = new XElement("email");
            doc.Root.Add(element);
            XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
            element.Document.Root.Add(
                new XAttribute(XNamespace.Xmlns + "xsi", xsi.ToString()));
            element.Add(new XAttribute(xsi + "nil", true));
    
            Console.WriteLine(doc);
        }
    }
    

    Output:

    <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <email xsi:nil="true" />
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XElement, called XUsers, that will contain XML which looks like this:
I have an XElement object which has a number of attributes and I simply
I want to find the Xelement attribute.value which children have a concrete attribute.value. string
I have an xelement which is basic html, i want to quickly loop through
EDIT: Switched from XmlTextWriter to XElement I have a Player class, which has following
I have 2 IEnumerables IEnumerable<float> Distance IEnumerable<XElement> Point which i want to convert into
I have XElement object which is my XML tree read from XML file. Now
So here's my case. I have an XElement, let's call it root, which has
I have the following XAttribute XElement.XAttribute(XName name): InjuredEmployeeName = e.Attribute(hciIIEmployeeName), which outputs an employee
I have a situation where we have a base class which several subclasses implement.

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.