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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:24:52+00:00 2026-06-02T02:24:52+00:00

I have this XNamespace ns = http://something0.com; XNamespace xsi = http://something1.com; XNamespace schemaLocation =

  • 0

I have this

XNamespace ns = "http://something0.com";
XNamespace xsi = "http://something1.com";
XNamespace schemaLocation = "http://something3.com";

XDocument doc2 = new XDocument(
    new XElement(ns.GetName("Foo"),
        new XAttribute(XNamespace.Xmlns + "xsi", xsi),
        new XAttribute(xsi.GetName("schemaLocation"), schemaLocation),
        new XElement("ReportHeader", GetSection()),
        GetGroup() 
    )
);

It gives

<?xml version="1.0" encoding="utf-8"?>
<Foo xmlns:xsi="http://something1.com"
xsi:schemaLocation="http://something3.com" 
xmlns="http://something0.com">
    <ReportHeader xmlns="">
        ...
    </ReportHeader>
    <Group xmlns="">
        ...
    </Group>
</Foo>

But I wan’t this result, how can it be done? (Notice the xmlns=""is missing..)

<?xml version="1.0" encoding="utf-8"?>
<Foo xmlns:xsi="http://something1.com"
xsi:schemaLocation="http://something3.com" 
xmlns="http://something0.com">
    <ReportHeader>
        ...
    </ReportHeader>
    <Group>
        ...
    </Group>
</Foo>
  • 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-02T02:24:54+00:00Added an answer on June 2, 2026 at 2:24 am

    Your problem here is that you are setting the default namespace for the document to “http://something0.com”, but then appending elements that are not in this namespace – they are in the empty namespace.

    Your document states it has a default namespace of xmlns=”http://something0.com”, but then you append elements which are in the empty namespace (because you didn’t supply their namespace when you appended them) – so they are all getting explicitly marked with xmlns=” to show they are not in the default namespace of the document.

    This means there are two solutions to getting rid of the xmlns=””, but they have different meanings:

    1) If you mean you definitely want the xmlns="http://something0.com" at the root element (specifying the default namespace for the document) – then to “disappear” the xmlns=”” you need to you need to supply this namespace when creating the elements:

    // create a ReportHeader element in the namespace http://something0.com
    new XElement(ns + "ReportHeader", GetSection())
    

    2) If these elements are not meant to be in the namespace
    “http://something0.com”, then you mustn’t add it as the default at
    the top of the document (the xmlns=”http://something0.com” bit on
    the root element).

    XDocument doc2 = new XDocument(
         new XElement("foo",  // note - just the element name, rather  s.GetName("Foo")
              new XAttribute(XNamespace.Xmlns + "xsi", xsi),
    

    The sample output you expect, suggests the former of these two choices.

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

Sidebar

Related Questions

In my feed generation code I have things like: XNamespace itunesNS = http://www.itunes.com/dtds/podcast-1.0.dtd; feed.ElementExtensions.Add(
I have this simplified version of my app in XAML: <UserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
I have an XML document that looks like this: <Data xmlns=http://www.domain.com/schema/data xmlns:dmd=http://www.domain.com/schema/data-metadata > <Something>...</Something>
Say I have a user control like this: <UserControl x:Class=StyleTest.UserControl1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have XML that looks something like this: <Root xmlns=http://widgetspecA.com/ns> ...any... <WidgetBox> <A/> <B/>
I have this web service : using System.Web.Services; namespace Contracts { [WebService(Namespace = http://tempuri.org/)]
I have this XSLT document : <xsl:stylesheet version=1.0 xmlns:mstns=http://www.w3.org/2001/XMLSchema xmlns=http://www.w3.org/2001/XMLSchema xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:msdata=urn:schemas-microsoft-com:xml-msdata xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output
I've a must to create wcf service with parameter. I'm following this http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8f18aed8-8e34-48ea-b8be-6c29ac3b4f41 First
Using this tutorial: http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx The web service is invoked such as Service1.asmx/HelloToYou The default
If I need to go from this service contract: [ServiceContract(Namespace=http://api.x.com/Svc1)] public interface IService1 {

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.