Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem with setting the value on a node of type element in xml

Posted on 2004-10-14
4
898 Views
Last Modified: 2008-02-01
Hi there,

I am trying to add a new record to my XML file. I was able to create the record and its fields, but when I tried to add values to the fields, I got the error: "Cannot set a value on node type: Element".

I am confident that I have something missing in my code, that it is not making it recognize the ability to set the value of my elements.

Here is a sample of my code:

        XmlDocument SrcDoc = new XmlDocument();
        SrcDoc.Load(xmlfile);
        XmlNode RootNode = SrcDoc.DocumentElement;

        //create a new table node
        XmlNode Newtable = SrcDoc.CreateNode(XmlNodeType.Element, "table", "");
        //create the sub node
        XmlNode ExtNode = SrcDoc.CreateNode(XmlNodeType.Element, "Ext","");
        //fill the data in ----------------------------------my error is here
        ExtNode.Value = newext;   // being passed to the subroutine

        //add the node to the new table node
        Newtable.AppendChild(ExtNode);
        //add the new table node to the root
        RootNode.AppendChild(Newtable);
        //save the docment back to the file
        SrcDoc.Save(xmlfile);


Thank you in advance for your prompt help.

yk
0
Comment
Question by:markataya
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Hans Langer earned 125 total points
ID: 12312422
replace this  

   //create a new table node
        XmlNode Newtable = SrcDoc.CreateNode(XmlNodeType.Element, "table", "");
        //create the sub node
        XmlNode ExtNode = SrcDoc.CreateNode(XmlNodeType.Element, "Ext","");
        //fill the data in ----------------------------------my error is here
        ExtNode.Value = newext;   // being passed to the subroutine

to


     //create a new table node
        XmlNode Newtable = SrcDoc.CreateElement("table");
        //create the sub node
        XmlNode ExtNode = SrcDoc.CreateElement("ext");
        //fill the data in ----------------------------------my error is here
        ExtNode.InnerText= newext;   // being passed to the subroutine


GL
0
 

Author Comment

by:markataya
ID: 12319669
Thank you! It works perfectly.

Is it possible to highlight the reason why the second case with CreateElement worked, while the CreateNode did not work?

Thank you again for your prompt response.

-yk
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12319794
the problem was just de
.value property
must be
.InnerText
Look at this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlxmlnodeclassvaluetopic.asp
GL
0
 

Author Comment

by:markataya
ID: 12321118
Thanks again for all the help!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question