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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:31:15+00:00 2026-05-27T18:31:15+00:00

I am adding a node to the XML file, but I need it to

  • 0

I am adding a node to the XML file, but I need it to be properly formatted. Could you assist with it?

        String newFile = System.IO.Path.GetFileName(textBox1.Text);

        //file name
        string filename = @"palette.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(filename);

        //create node and add value
        XmlNode node = doc.CreateNode(XmlNodeType.Element, "item", null);

        //create title node
        XmlNode nodeTitle = doc.CreateElement("name");
        //add value for it
        nodeTitle.InnerText = @"<![CDATA["+newFile+"]]>";

        //create Url node
        XmlNode nodeUrl = doc.CreateElement("imgfile");
        nodeUrl.InnerText = newFile;

        //add to parent node
        node.AppendChild(nodeTitle);
        node.AppendChild(nodeUrl);

        //add to elements collection
        doc.DocumentElement.AppendChild(node);

        //save back
        doc.Save(filename);

The XML should be looking like that:

  <item>
  <name><![CDATA[panda.gif]]></name>
  <imgfile>panda.gif</imgfile>
  </item>

but it look like that:

  <item>
  <name>&lt;![CDATA[panda.gif]]&gt;</name>
  <imgfile>panda.gif</imgfile>
  </item>
  • 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-27T18:31:16+00:00Added an answer on May 27, 2026 at 6:31 pm

    There is a method you can use to wrap cdata it is.

    XMLNode.AppendChild( XMLDocument.CreateCDataSection( newFile ) );
    

    It XMLDocument.CreateCDataSection returns XmlCDataSection object which you can append to your node and it will wrap your file in CDATA.

    Check this out for more information: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createcdatasection.aspx

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

Sidebar

Related Questions

If I get the path to a specific node as a string can I
This is the same question as: Explicit Element Closing Tags with System.Xml.Linq Namespace but
I am parsing xml file and adding the attribute values in a NSMutableArray as
I am trying to reformat XML adding intermediate level node. Here is what I
Using Jquery I am parsing an XML file and adding an attribute to every
If I output the string before adding it as a text node to the
I can copy a node from one XML file to another using org.w3c.dom.Document. importNode(Node
Which XML structure allows me faster adding,deleting,updating of a node? My assumption is the
I am looking for a recipe for adding Drupal node records. I have identified
Adding Exceptional Handling is a good practise, but I have a doubt, In our

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.