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

  • Home
  • SEARCH
  • 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 7617245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:06:03+00:00 2026-05-31T03:06:03+00:00

Am creating an xml file using xmlwriter,i thought it works fine but when i

  • 0

Am creating an xml file using xmlwriter,i thought it works fine but when i try to validate it fails bcoz there is spl character (BOM) appears like below,just gone thru forum seen lot of people adive me to use “SecurityElement.Escape”. Am not sure how and where.Some one please guide me to remove this spl charecter from the xml file.

<?xml version="1.0" encoding="utf-8"?>

if found the code for the above symbol

It look like &#195;&#175;&#194;&#187;&#194;&#191;&#060;

My Code

             XmlWriter xmlWrite;
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.OmitXmlDeclaration = true;
                xmlWrite = XmlWriter.Create(@"c:\test.xml",settings);
            xmlWrite.WriteStartElement("metadata");
            xmlWrite.WriteElementString("story", story);
            xmlWrite.Close();

i can succesfully remove the version but still the spl characters are there . Am stuck now.

Any help ?

This is the Answer to help me to get rid of the spl char

                    XmlWriter xmlWrite;
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Encoding = new UTF8Encoding(false);//Thanks to DaveE
                    settings.ConformanceLevel = ConformanceLevel.Fragment;
                    settings.OmitXmlDeclaration = true;
                    xmlWrite = XmlWriter.Create(@"c:\test.xml",settings);

when am append i used “using (TextWriter sw = new StreamWriter(@”c:\test.xml”)) to work it out

 XmlDocument doc = new XmlDocument();
           doc.Load(@"C:\test.xml");
            XmlNode newChild = doc.CreateNode(XmlNodeType.Element, "image", null);
            var attribute = doc.CreateAttribute("name");
            attribute.Value = nameOnly;
            newChild.Attributes.Append(attribute);
            XmlNode xmlElement = doc.CreateNode(XmlNodeType.Element, "width", null);
            xmlElement.InnerText = widthValue[1].TrimStart();
            newChild.AppendChild(xmlElement);
            using (TextWriter sw = new StreamWriter(@"C:\test.xml")) 
            {
                doc.Save(sw);

            }
  • 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-31T03:06:04+00:00Added an answer on May 31, 2026 at 3:06 am

    When you say you “try to validate it”, what do you mean? XML validators shouldn’t have any trouble with a BOM. And escaping the BOM is going to produce invalid XML.

    If you want to us XMLWriterSettings, you need to create it, set the values you want, then use it when you create the XMLWriter. XMLWriter.Settings is read-only.

    XmlWriterSettings settings = new XmlWriterSettings();
    settings.ConformanceLevel = ConformanceLevel.Fragment;
    settings.OmitXmlDeclaration = true;
    
    writer = XmlWriter.Create("c:\test.xml", settings);
    

    That doesn’t look like a normal BOM there, btw. Some of the bytes are correct, but there’s junk in it. What code page is set on your system?

    EDIT: Add Encoding to your XMLWriterSettings object:

    settings.Encoding = new UTF8Encoding(false);

    The ‘false’ parameter tells the Encoding not to use a BOM.

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

Sidebar

Related Questions

I'm creating a xml-file for display in Excel using _di_IXMLDocument. But for some tags
I am creating a Xml like format using XmlWriter . But in the output
I am creating an XML file from scratch using PHP's SimpleXML Object. But I
I'm creating an XML file using Perl and XML::Simple module. I successfully create the
In C#, I'm creating an XML file from a DataTable using dataTable.WriteXml(filePath), and get
I am using XML file for creating Context Menu for my ListView. (Please see
Using MSXML4, I am creating and saving an xml file: MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc; //add some
I'm using XML for a config file in PHP (Using SimpleXML), in creating the
I am creating an XML file using the System.Xml.Serialization module. I have a class
I have a DataTable that I'm creating an XML file from using .WriteXML(..), although

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.