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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:21:17+00:00 2026-06-13T23:21:17+00:00

I have a string like this on C#: string sxml=<id>xpto</id> and I want to

  • 0

I have a string like this on C#:

string sxml="<id>xpto</id>"

and I want to save an xml file using XLinq:

XElement cursosXML = new XElement("MenuItem", new XCData(sxml));
cursosXML.save("C:\\xpto.xml")

when I read my xml file this appears:

<MenuItem><![CDATA[<id>xpto</id>]]></MenuItem>

but I do not want <![CDATA[

How can I get this result?

<MenuItem>&lt;xpto&gt;3&lt;</MenuItem>
  • 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-13T23:21:18+00:00Added an answer on June 13, 2026 at 11:21 pm

    Here’s how you should add the string to your element

            XElement sxml = XElement.Parse("<id>xpto</id>");
            XElement cursosXML = new XElement("MenuItem", sxml);
            cursosXML.Save("C:\\xpto.xml");
    

    Below Is an explanation of the troubles you’ve been having. It’s just here for your reference

    <id>xpto</id> is an XML Element, but you’re adding it to your current element as though it were a literal string. When you do this, the computer doesn’t think you’re adding a new child element to your main element, so it escapes it(explained later)

    The code I posted calls XElement.Parse(string), which will take your seralized xml string, and try to generate a valid XElement from it.

    What’s happening is that &lt; is an escape sequence for < and &gt; is an escape sequence for >.

    the reason why your XML parser escapes < and > is because those characters have special meaning, and including them in your XML change the nature of XML.

    It’s kinda similar to how \n is an escape sequence for the newline character, and how \\ is an escape sequence for \

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

Sidebar

Related Questions

I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have a string like this in C#: string a = A|B|C|D I want
I have a string like this field1=1 field2=2 field3=abc I want to ouput this
I have a string like This is a test . I want to split
I have a string like this: S=str1|str2|str3 I want extract another string from S
I have string like this 0100110011001 I want to convert it to byte array
I have string like this: $str = old iccid : 809831 3245 345 new
I have string like: This.is.a.great.place.too.work. (or) This/is/a/great/place/too/work/ I want to see if this string
I have string like this: $str = old iccid : 809831 3245 345 new

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.