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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:41:02+00:00 2026-06-09T19:41:02+00:00

Thanks for taking the time to possibly help me out! I am currently having

  • 0

Thanks for taking the time to possibly help me out!

I am currently having two problems, and I think that one is causing the other. Basically I am trying to insert an extra node into an existing XML file, and then fill it with data from a dataGridView. Here is the XML I am trying to change, i need to add the “Language” tag:

<stentry>
  <index>28</index>
  <sid>PARAM_TITLE1</sid>
  <val>
    <en>Param 1</en>
    <es>parámetro 1</es>
    ***<Language>String<language>***
  </val>
  <params>
    <fontref>187</fontref>
    <numref>0</numref>
    <clip>FALSE</clip>
    <include>FALSE</include>
    <protected>FALSE</protected>
    <cwidth>-1</cwidth>
    <dwidth>0</dwidth>
  </params>
</stentry>

However I am also faced with the issue that the tag is used elsewhere:

<module>
  ..
  <color>
    <name>DIALOG</name>
    <val>ffd4dbee</val>
   <id>41a</id>
  </color>
  <color>
    <name>WIDGET_FILL</name>
    <val>ffc0c0c0</val>
    <id>41c</id>
 </color>
 ..
</module>

Currently I am using this method to insert the data:

int n = 0;

XmlNodeList nodeList = xDoc.GetElementsByTagName("val");
foreach (XmlNode node in nodeList)
{
    if (node.OuterXml.Contains("val"))
    {
        XmlElement newElement = xDoc.CreateElement(tag);
        **string data = dataGridView1.Rows[n].Cells[3].Value.ToString();**
        XmlText txtVal = xDoc.CreateTextNode(data);
        XmlNode parent1 = node.ParentNode;
        parent1.AppendChild(newElement);
        parent1.LastChild.AppendChild(txtVal);
        n++;
    }
}

The problem being that at the moment I get a NullReferenceException on the highlighted line. I believe this is because there is data being put into the incorrect tags ahead of where it needs to be. So when it tries to put data in where it is needed the value is null. But I am not 100% on this, so I have come seeking help.

Thanks a lot!

  • 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-09T19:41:04+00:00Added an answer on June 9, 2026 at 7:41 pm

    If the line you have highlighted is throwing a NullReferenceException then it isn’t your XML that is faulty, it’s your accessing of a cell in dataGridView1. Stick a breakpoint on that line, and when you hit it, inspect the properties down the chain to see where the null is coming. This should help you see where the exact problem is. You can do this by hovering over each property in turn when the breakpoint is on that line.

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

Sidebar

Related Questions

Thanks for taking some time to help me out. Using: Microsoft Visual C# 2010
Thanks for taking the time out to read. I have a folder of MP3
Problem: Thanks for taking the time to read this. I'm having a problem which
Firstly, thanks for taking the time to read this and possibly comment on it.
thanks for taking the time to look at my question. I've been diving into
Thanks for taking the time to read this. I have an unknown number of
thanks for taking the time to stop by my question. Below you will find
first of all thanks for taking your time! I'm a junior Dev, working with
First of all thanks for taking the time to look into this. I store
Thanks everyone for taking the time to read this. I have styled my navigation

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.