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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:02:11+00:00 2026-06-13T00:02:11+00:00

I have an xmldocument that i’m loading xml in to. The xml looks like

  • 0

I have an xmldocument that i’m loading xml in to.

The xml looks like this:

<Table1>
  <buyer_id>0</buyer_id>
  <buyername>CompanyA</buyername>
  <address1>123 Simpsons Dr.</address1>
  <address2/>
  <city>Springfield</city>
  <state>ST</state>
  <postalcode>12345</postalcode>
  <eaddress/>
  <phone/>
  <fax/>
</Table1>

I’m looping through looking at each CompanyA entry and setting innertext accordingly. I’m using the following code to insert inner text into elements that meet the criteria:

XmlDocument dom = new XmlDocument();
dom.LoadXml(xmlString);

XmlNodeList elemList = dom.GetElementByTagName("Table1");
for(int i = 0; i < elemList.Count; i++)
{
   if(dom.GetElementsByTagName("buyername").Item(i).InnerText.Contains("CompanyA")
   {
      dom.GetElementsByTagName("address1").Item(i).InnerText = "SomeInfo";
   }
}

Using the above code, the value of address1(123 Simpsons Dr.) would be replaced by “SomeInfo”. I would like to instead insert “SomeInfo” into the address2 element but when I try using:

dom.GetElementsByTagName("address2").Item(i).InnerText = "SomeInfo";

I get an error. I’m able to insert innertext into any element that already has a value but I cannot when the element is empty (such as <address2/>). Thoughts?

  • 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-13T00:02:12+00:00Added an answer on June 13, 2026 at 12:02 am

    Use LINQ2XML.It’s a complete replacement to other XML api’s like the dirty old idiot XmlDocument

    XElement doc=XElement.Load("yourXml.xml");
    
    foreach(var elm in doc.Descendants("Table1"))
    {
    if(elm.Element("buyername").Value=="CompanyA")
    elm.Element("address2").Value="SomeInfo";
    }
    doc.Save("yourXml.xml");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml document that looks like this. <foo> <bar type=artist/> Bob Marley
I have a XML file that looks like this <Licence> <Name>Test company</Name> <Version>1.1.1.1</Version> <NumberOfServer>2</NumberOfServer>
I have a xml doxument that looks like this: <create> <customers> <customer> <first-name>foo</first-name> <last-name>bar</last-name>
I have some XML that looks like this: <abc x={></abc> I want to force
I have an XML document that matches our site navigation something like this: <page
I have XmlDocument. I don't know XPath, I only know that this xml document
I have written some code that loads an XML document using an XmlDocument object
This is a tough one to google for. I have an XML document that's
I have the following XML that is built up at runtime using an XmlDocument
I have a XmlDocument like this: <Root> <Settings> <PresentationSettings> </PresentationSettings> </Settings> </Root> When I

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.