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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:52:50+00:00 2026-05-27T10:52:50+00:00

I am adding XmlElement to an existing document but an extra attribute is being

  • 0

I am adding XmlElement to an existing document but an extra attribute is being added. Here is the code:

XmlNode manifest = this.getManifestNode ();
XmlElement manifestEntry = _content.CreateElement ("item", _contentPath);
XmlAttribute id = _content.CreateAttribute ("id"); 
id.Value = "content" + getManifestNodes ().Count;
XmlAttribute href = _content.CreateAttribute ("href"); 
href.Value = splitPath [splitPath.Length - 1]; 
XmlAttribute mediaType = _content.CreateAttribute ("media-type"); 
mediaType.Value = "application/xhtml+xml"; 
manifestEntry.Attributes.Append (id); 
manifestEntry.Attributes.Append (href); 
manifestEntry.Attributes.Append (mediaType); 
manifest.AppendChild (manifestEntry);

and the resulting XML:

<item id="content3" href="test1.html" media-type="application/xhtml+xml" xmlns="/home/jdphenix/epubtest/test/OEBPS/content.opf" />

Where is the

xmlns="/home/jdphenix/epubtest/test/OEBPS/content.opf"

coming from? The path that it adds is the location of the document on disk, but I’m not adding it in my code (atleast, that I am aware of). Let me know if you need to know more details.

Edit: I modified my code per Filburt’s suggestion and changed

XmlElement manifestEntry = _content.CreateElement ("item", _contentPath);

to

XmlElement manifestEntry = _content.CreateElement ("item");

This is a step in the right direction, but produces the following XML:

<item id="content3" href="test1.html" media-type="application/xhtml+xml" xmlns="" />
  • 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-27T10:52:50+00:00Added an answer on May 27, 2026 at 10:52 am

    You’re adding this namespace yourself (Line 2):

    XmlElement manifestEntry = _content.CreateElement ("item", _contentPath);
    

    See XmlDocument.CreateElement Method (String, String) – the first String parameter is the qualified name of the element you are adding and the second string is the namespace.

    Try

    XmlElement manifestEntry = _content.CreateElement ("item");
    

    and everything should be fine.

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

Sidebar

Related Questions

Adding a comment such as this: // TODO: Refactor this code ...creates a task
I'm currently trying to find a way of adding some extra elements to existing
Adding Exceptional Handling is a good practise, but I have a doubt, In our
Adding the row one by one in the button click.. (i tried but its
I'm having trouble adding an XmlElement to a non-root element in PowerShell. Basically, given
This is the same question as: Explicit Element Closing Tags with System.Xml.Linq Namespace but
This is a real newbie question, but I am struggling to get this to
I'm trying to modify an XML document. The XML is structured like this: <?xml
I assume that there is probably no satisfactory answer to this question, but I
i am reading an XML feed and adding results like this: XElement _xml; try

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.