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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:43:02+00:00 2026-05-27T09:43:02+00:00

I have a xml like this: <?xml version=1.0 encoding=utf-8?> <assessment xmlns=http://xml.thinkcentral.com/pub/xml/hsp/assessment xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xhtml=http://www.w3.org/1999/xhtml xmlns:tia=http://xml.thinkcentral.com/pub/xml/hsp/tia

  • 0

I have a xml like this:

<?xml version="1.0" encoding="utf-8"?>
<assessment xmlns="http://xml.thinkcentral.com/pub/xml/hsp/assessment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:tia="http://xml.thinkcentral.com/pub/xml/hsp/tia" xmlns:tibase="http://xml.thinkcentral.com/pub/xml/hsp/tibase" xsi:schemaLocation="http://xml.thinkcentral.com/pub/xml/hsp/assessment http://xml.thinkcentral.com/pub/xml1_2_6/hsp_assessment.xsd" isbn="9780547660455" buid="NA12_AG_G01CH01A" title="Chapter 1 Test Form A" num_questions="24" num_sections="1" type="Basal" intervenable="true" duration="P5Y" pausable="false" scramble="false">
  <test_section id="1" name="Chapter 1 Test Form A" index="1">
    <aaa testitem_id="NA12_AG_G01CH01A_01" template="hsp_testitem_mc1.xslt" id="1" bankable="true">
      <tia:multipleChoiceTestItem total-points="1" questionType="Multiple Choice" sample="false" version_label="1.0">
        <tia:directions>
          <tia:tiDirectionLine>
            <tia:textBody></tia:textBody>
          </tia:tiDirectionLine>
          <tia:address>Richtextbox Data</tia:address>
        </tia:directions>
      </tia:multipleChoiceTestItem>
    </aaa>
    <aaa testitem_id="NA12_AG_G01CH01A_02" template="hsp_testitem_mc1.xslt" id="2" bankable="true">
      <tia:multipleChoiceTestItem total-points="1" questionType="Multiple Choice" sample="false" version_label="1.0">
        <tia:directions>
          <tia:tiDirectionLine>
            <tia:textBody></tia:textBody>
          </tia:tiDirectionLine>
          <tia:address>Richtextbox Data</tia:address>
        </tia:directions>
      </tia:multipleChoiceTestItem>
    </aaa>
  </test_section>
</assessment>

I have to insert the the data according to the id of the aaa element.

<aaa testitem_id="NA12_AG_G01CH01A_01" template="hsp_testitem_mc1.xslt" id="1" bankable="true">
<aaa testitem_id="NA12_AG_G01CH01A_02" template="hsp_testitem_mc1.xslt" id="2"bankable="true">

if id=”1″ then data of ritchtextbox will be insert into tia:address node.

i am using the following code.

    private void button2_Click(object sender, EventArgs e)
    {
        XDocument doc = XDocument.Load(@"d:\file.xml");


      XNamespace ns = XNamespace.Get("http://tia.com");           

    var result=  (from ele in doc.Descendants("aaa")
       where ((string)ele.Attribute("id")) == "1"
       select ele.Element(ns+"address")).FirstOrDefault(); 




        if (result != null)
        {
            result.Value = richTextBox1.Text;

            doc.Save(@"d:\file.xml");
        }
        MessageBox.Show("done");

    }

its not working. how i do that?

  • 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-27T09:43:03+00:00Added an answer on May 27, 2026 at 9:43 am

    First of al, the XML markup you have posted is not valid. I think the easiest way to read/write an XML document is Linq-XML. You have to import System.Xml.Linq namespace to use XDocument class and its method. Take a look at MSDN article.

    XDocument doc = XDocument.Load(@"c:\file.xml");
    
    var result = (from ele in doc.Descendants("aaa")
                    where ((string)ele.Attribute("id")) == "1"
                    select ele.Element("address")).FirstOrDefault();
    
    if (result != null)
    {
        result.Value = richTextBox1.Text;
        doc.Save(@"c:\file.xml");
    }
    

    XML document should be:

    <?xml version="1.0" encoding="utf-8"?>
    <root>
      <aaa id="1">
        <address>Hello World</address>
      </aaa>
      <aaa id="2">
        <address>
          write text of ritchtextbox here</address>
      </aaa>
    </root>
    

    EDIT:

    In OP, XML markup has some issues and I’ve fixes the markup (added namespace).

    <?xml version="1.0" encoding="utf-8"?>
    <aaa testitem_id="chapter1" template="hsp_testitem_mc1.xslt" id="1" bankable="true" xmlns:tia="http://tia.com">
      <tia:multipleChoiceTestItem total-points="1" questionType="Multiple Choice" sample="false" version_label="1.0">
        <tia:directions>
          <tia:tiDirectionLine>
            <tia:textBody />
          </tia:tiDirectionLine>
          <tia:address>I have to edited here.(Richtextbox data)</tia:address>
        </tia:directions>
      </tia:multipleChoiceTestItem>
    </aaa>
    

    Code to find <tia:address> and replace its value.

    XDocument doc = XDocument.Load(file);
    
    XNamespace ns = XNamespace.Get("http://tia.com");
    
    var result = (from ele in doc.Descendants(ns + "address")
                    select ele).SingleOrDefault();
    
    if (result != null)
    {
        result.Value = richTextBox1.Text;
        doc.Save(file);
    }
    

    EDIT : After changes made by OP in opening post.

        XDocument doc = XDocument.Load(file);
        //Change the namespace
        XNamespace ns = XNamespace.Get("http://xml.thinkcentral.com/pub/xml/hsp/tia");
        var result = (
                     from ele in doc.Descendants(ns + "multipleChoiceTestItem")
                     where ele.Parent.Attribute("id").Value == "1"
                     select 
                        ele.Descendants(ns+"address").FirstOrDefault()
                     ).FirstOrDefault();
    
        if (result != null)
        {
            result.Value = "World";
            doc.Save(file);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a style sheet like this <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:param
I have a SOAP Call that looks like this: <?xml version=1.0 encoding=utf-8?><soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/ xmlns:soapenc=http://schemas.xmlsoap.org/soap/encoding/
hi i have an xml like this <?xml version=1.0?> <DataSetExchangeWMS xmlns=http://tempuri.org/DataSetExchangeWMS.xsd> <dtObjektInfo> <LanguageCode>1031</LanguageCode> <LiegenschaftID>7463</LiegenschaftID>
have an xml file like this. <?xml version =1.0 encoding =utf-8?> <menu> <menuNode title=Register
I have an xml file which looks like this <?xml version=1.0 encoding=UTF-8 ?> <BulkDataExchangeRequests
I have a simple XML file like so: <?xml version=1.0 encoding=UTF-8?> <foo attr=blah &#176;
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <game> <name>Space Blaster</name> <description></description> <version>1</version> <fullscreen>false</fullscreen>
An example XML file is this: <?xml version=1.0 encoding=UTF-8?> <game> <name>bomber</name> <behaviors-used> <behavior id=Bullet
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>

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.