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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:53:36+00:00 2026-06-07T08:53:36+00:00

XDocument doc = XDocument.Parse(_data) XElement root = new XElement(student); doc.Element(marks).Add(root); doc.Save(_data) the _data is

  • 0
            XDocument doc = XDocument.Parse(_data)
           XElement root = new XElement("student");
           doc.Element("marks").Add(root);
             doc.Save(_data)

the _data is the deserialized string xml and student is the root tag want to add
doc.save throws the error.How to save the root tag ?

the string xml

             <marks>
           <name>Martin</name> 
           <date>3/24/2012</date> 
           <field>Percent</name> 
           <new>33.3</new> 
           <old>10</old> 
            </marks> 

this is the string xml before root tag is added, once it is added it should look like
after the root tag is added it should look like

             <student>
            <marks>
           <name>Martin</name> 
           <date>3/24/2012</date> 
           <field>Percent</name> 
           <new>33.3</new> 
           <old>10</old> 
            </marks> 
            </student>
  • 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-07T08:53:37+00:00Added an answer on June 7, 2026 at 8:53 am

    XDocument.Parse(_data)

    implies that _data is XML, ie "<tag> <sub /> </tag>"

    doc.Save(_data)

    Requires _data to be a valid filename. Like "output.xml"

    Ok, seems that you need:

    //doc.Save(_data)
    _data = doc.ToString();
    

    Take 3:

    You need to add the existing xml to <Student>, not the other way around.

    //untested    
    XElement doc = XElement.Parse(_data);  // not XDoc
    XElement root = new XElement("student", doc);
    //doc.Save(_data)
    _data = root.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code List<string> IDs = new List<string>(); XDocument doc = XDocument.Parse(xmlFile); var
I am having the below code. import xml.dom.minidom def get_a_document(name): return xml.dom.minidom.parse(name) doc =
private void BindCountry() { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(countries.xml)); foreach (XmlNode node in
here's my code: XmlDocument doc = new XmlDocument(); foreach (string c in colorList) {
I am Trying to export xml from some data in C# XDocument doc =
This is what I've been trying: pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(Book.xml); // need
I have the following code: String website = http://www.somewebsite.com/; Document doc = Jsoup.connect(website).get(); Elements
byte[] mediaBytes = Convert.FromBase64String(<<strings>>); XpsDocument doc; ms = new MemoryStream(mediaBytes, 0, mediaBytes.Length); Uri DocumentUri
I am trying to parse the following XML file in Java and to store
I am trying to parse a XML document using Xerces, but I cant seem

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.