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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:20:11+00:00 2026-06-18T03:20:11+00:00

In my c# application i am creating an xml based on the database value.

  • 0

In my c# application i am creating an xml based on the database value. It woks fine until the string is not a special character. Below is my code.

 XmlDocument doc = new XmlDocument();
 XmlElement element = doc.CreateElement("NewDataSet");
  ------
 string itemname =System.Web.HttpUtility.HtmlEncode(ds.Tables[0].Rows[j]["itemname"].ToString());
 fieldElement = doc.CreateElement(itemname);
 fieldElement.InnerText = ds.Tables[0].Rows[j]["count"].ToString();
 fieldElement1.AppendChild(fieldElement);

where i am getting error in `fieldElement = doc.CreateElement(itemname);
as The ‘ ‘ character, hexadecimal value 0x20, cannot be included in a name.
And the string which throws exception is “Adam & Eva frisør”.

Can anyone tell me how to overcome this problem.

  • 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-18T03:20:12+00:00Added an answer on June 18, 2026 at 3:20 am

    There are two possible issue here. Firstly, you are html encoding the element name. This will work fine until the element name contains a special character.

    The element tags are case-sensitive; the beginning and end tags must
    match exactly. Tag names cannot contain any of the characters
    !”#$%&'()*+,/;<=>?@[]^`{|}~, nor a space character, and cannot start
    with -, ., or a numeric digit.

    so, it is an error waiting to happen. Ensure that the name is valid and does not contain any special characters.

    Secondly, you are not escaping the content of the element. The text you have quoted contains an unescaped &. This is causing the actual error you are getting. Use the same escape method you are using for the element name for the element text.

    fieldElement.InnerText = System.Web.HttpUtility.HtmlEncode(ds.Tables[0].Rows[j]["count"].ToString());
    fieldElement1.AppendChild(fieldElement);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an XML based application in which I have to fetch data
Im creating application in java using XML. XML- <?xml version=1.0 encoding=UTF-8?> <songlist id=slist> <song
I am creating a VB6 application, which reads information from an XML file and
I am creating an application and I need to connect to a database. The
I am creating an iOS application that I need to connect to a database
I am creating one simple conference application (Java based) and using RESTFull Web Service
I am trying to override a parameter in my application's web.xml file by creating
I'm creating an application that will POST an xml file to an SAP PI
We are creating many XML files for a single app in developing android applications;
I am creating application where in i have used preferences for changing font settings.

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.