Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-14
4
Medium Priority
?
926 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 500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

772 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