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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:08:10+00:00 2026-06-01T20:08:10+00:00

In an XmlDocument, either when writing and modify later, is it possible to remove

  • 0

In an XmlDocument, either when writing and modify later, is it possible to remove the self-closing tags (i.e. />) for a certain element.

For example: change

  • <img /> or <img></img> to <img>.
  • <br /> to <br>.

Why you ask? I’m trying to conform to the HTML for Word 2007 schema; the resulting HTML will be displayed in Microsoft Outlook 2007 or later.

After reading another StackOverflow question, I tried the setting the IsEmpty property to false like so.

var imgElements = finalHtmlDoc.SelectNodes("//*[local-name()=\"img\"]").OfType<XmlElement>();
foreach (var element in imgElements)
{
    element.IsEmpty = false;
}

However that resulted in <img /> becoming <img></img>. Also, as a hack I also tried changing the OuterXml property directly however that doesn’t work (didn’t expect it to).

Question

Can you remove the self-closing tags from XmlDocument? I honestly do not think there is, as it would then be invalid xml (no closing tag), however thought I would throw the question out the community.

Update:

I ended up fixing the HTML string after exporting from the XmlDocument using a regular expression (written in the wonderful RegexBuddy).

    var fixHtmlRegex = new Regex("<(?<tag>meta|img|br)(?<attributes>.*?)/>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
    return fixHtmlRegex.Replace(htmlStringBuilder.ToString(), "<$1$2>");

It cleared many errors from the validation pass and allow me to focus on the real compatibility problems.

  • 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-01T20:08:12+00:00Added an answer on June 1, 2026 at 8:08 pm

    You’re right: it’s not possible simply because it’s invalid (or rather, not well-formed) XML. Empty elements in XML must be closed, be it with the shortcut syntax /> or with an immediate closing tag.

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

Sidebar

Related Questions

Whats the best way to read Xml from either an XmlDocument or a String
I've got an XML document that is in either a pre or post FO
I am saving an XMLDocument object to disk using the Save (string) function .
I generate a XMLDocument based on a dataset by binding the dataset to the
I have an XmlDocument that is from a webservice, and I want to use
In my code: XmlDocument document = new XmlDocument(); XmlElement book = document.CreateElement(book); document.AppendChild(book); ...
private void BindCountry() { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(countries.xml)); foreach (XmlNode node in
I have a XmlDocument which is not properly formed <library> <dept> <books></books> <language></language> </dept>
here's my code: XmlDocument doc = new XmlDocument(); foreach (string c in colorList) {
i am creating XmlDocument by code and adding some tag. The structure is like

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.