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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:44:32+00:00 2026-05-29T22:44:32+00:00

I was trying to append the xml file in the existing file, everything works

  • 0

I was trying to append the xml file in the existing file, everything works fine but I have an issue with default namespace when it appends.

This is the code I use to append:

 XmlNode newChild = doc.CreateNode(XmlNodeType.Element, "image", "");
    newChild.Attributes.Append(doc.CreateAttribute("name", filename));

    XmlNode xmlElement = doc.CreateNode(XmlNodeType.Element, "width", null);
    xmlElement.InnerText = widthValue[1].TrimStart();
    newChild.AppendChild(xmlElement);

am getting an output like below

<image d2p1:name="" xmlns:d2p1="test.jpg">
    <width>1024</width>
</image>

but I was trying to append like:

<image name="test.jpg">
    <width>1024</width>
</image>
  • 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-29T22:44:35+00:00Added an answer on May 29, 2026 at 10:44 pm

    As others suggested, using LINQ to XML might be easier in general.

    But if you want to stick with using XmlDocument, to fix the issue, change your code to the following:

    var attribute = doc.CreateAttribute("name");
    attribute.Value = filename;
    newChild.Attributes.Append(attribute);
    

    The problem with the code you have is that doc.CreateAttribute("foo", "bar") creates an attribute with the name foo in a namespace with the URI bar. That’s really not what you want.

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

Sidebar

Related Questions

I'm using XmlDocument and XmlWriter to append XML into an existing file, but my
I'm trying to append a list of Columns to this xml file: <?xml version=1.0
Here's the problem I have a xml file that I am trying to append
I'm trying to import an xml file into vb.net XmlDocument but am getting the
I have an xml file that looks like this: <!DOCTYPE ROOT SYSTEM zombie.dtd> <ROOT>
I am trying append some XML retrieved via a dojo.XHRGet to a dijit.layout.ContentPane .
I am trying to append to a log file, using HTML tables format for
I'm trying to append a string of svg elements to the dom. This is
I'm trying to append items to a QList at runtime, but I'm running on
I'm trying to append text lines with this code SendMessage(Form1.log.Handle, WM_SETTEXT, 0, Integer(PChar(textLog))); //

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.