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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:12:43+00:00 2026-06-15T03:12:43+00:00

Given the following XDocument , initialized into variable xDoc : <Report xmlns=http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition> <ReportSection> <Width

  • 0

Given the following XDocument, initialized into variable xDoc:

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
  <ReportSection>
    <Width />
    <Page>
  </ReportSections>
</Report>

I have a template embedded in an XML file (let’s call it body.xml):

<Body xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
  <ReportItems />        
  <Height />
  <Style />
</Body>

Which I would like to put as a child of <ReportSection>. Problem is if add it through XElement.Parse(body.xml), it keeps the namespace, even though I would think namespace should be removed (no point in duplicating itself – already declared on the parent). If I don’t specify namespace, it puts an empty namespace instead, so it becomes <Body xmlns="">.

Is there a way to properly merge XElement into XDocument? I would like to get the following output after xDoc.Root.Element("ReportSection").AddFirst(XElement):

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
  <ReportSection>
    <Body>
      <ReportItems />        
      <Height />
      <Style />
    </Body>
    <Width />
    <Page>
  </ReportSections>
</Report>
  • 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-15T03:12:44+00:00Added an answer on June 15, 2026 at 3:12 am

    I’m not sure why this is happening, but removing the xmlns attribute from the body element seems to work:

    var report = XDocument.Parse(
    @"<Report xmlns=""http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"">
      <ReportSection>
        <Width />
        <Page />
      </ReportSection>
    </Report>");
    
    var body = XElement.Parse(
    @"<Body xmlns=""http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"">
      <ReportItems />        
      <Height />
      <Style />
    </Body>");
    
    XNamespace ns = report.Root.Name.Namespace;
    if (body.GetDefaultNamespace() == ns)
    {
       body.Attribute("xmlns").Remove();
    }
    
    var node = report.Root.Element(ns + "ReportSection");
    node.AddFirst(body);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following Xml: <Animals xmlns=http://www.company.com/Global/US> <Mammals> <Animal> <Type> <Name>Cat</Name> <Breed>Ally Cat</Breed> </Type> <Color>
Given the following xml: <Document xmlns=urn:company.com:catalog.01 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <book> <author>Wells</author> </book> </Document> With Xerces the
Given the following: - <ArrayOfWsParcelDocIndexIAS xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> - <wsParcelDocIndexIAS> <locatorNum xmlns=http://xxx/webservices/wsDocumentIndex/>131312</locatorNum> <docType xmlns=http://xxx/webservices/wsDocumentIndex/>KIOOLX_DOCINDEX</docType> <docID
Given the following XML <?xml version=1.0?> <Message> <ArrayOfStock xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <Stock> <StockID>9cddb639-25ee-4415-be07-3109e5ae9883</StockID> <Description>Stock Item
I am following given upload-a-vhd help document to create my openSuse linux vhd: https://www.windowsazure.com/en-us/manage/linux/common-tasks/upload-a-vhd/
Given the following code: <!DOCTYPE html> <!-- HTML5 --> <html> <head> <meta http-equiv="Expires" content="Fri,
Given the following XML: <?xml version=1.0 encoding=UTF-8 ?> <?xml-stylesheet type=text/xsl href=form.xsl?> <Document> <Translations> <Translation
// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?

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.