Hi
When using XmlDocument, I can create nodes and attributes as I like. What I
didn't achieve is changing the Value of a node (created with createElement),
it claims that it's the wrong node type. When changing the InnerText, I
loose all child nodes. When cloning the node and reassigning the child nodes
of the original node to the cloned node, the children are not visilble in
the InnerXml.
To make it simple. How do I change the value of a node without loosing its
children?
Any hints are appeaciated.
Thanks, Urs 2 1723
"Urs Vogel" <uv****@msn.com > wrote in message news:O$******** ******@TK2MSFTN GP14.phx.gbl... What I didn't achieve is changing the Value of a node (created with createElement), it claims that it's the wrong node type.
This is correct. Elements have no Value in the DOM. They have
child nodes. Think of them as containers of other nodes, not
terminal nodes.
When cloning the node and reassigning the child nodes of the original node to the cloned node,
I'd like to see the code of exactly how these reassignments are
being performed before commenting on why the child nodes
may not be visible in the InnerXml (if the nodes are properly
moved from the original element's children to the new - cloned
- element then it should work); but did you know you could also
do a "deep copy" clone by passing a boolean argument of true
to the CloneNode( bool) method if all you're going to do is
copy the original element's children anyway.
To make it simple. How do I change the value of a node without loosing its children?
Recognize the difference between nodes and elements (Elements
are nodes, but not all nodes are elements).
Then change the child nodes of the element. All an element has,
besides it's identity (QName: in the Prefix, LocalName and Name-
spaceUri properties), and attributes (GetAttributes( int)) -- is it's
children.
Also (purely speculating), make sure if you're cloning the element
and changing it, that you remember to ReplaceChild( ) the new
element for the original element at the appropriate position in the
document's node tree. It's not enough to merely CreateElement( )
as you must also remember to attach that element at the correct
spot in its owner document.
Derek Harmon
Derek
Thanks! By changing the code from .RemoveNode/.AppendChild to ReplaceNode(),
it works. Great!!
if(xNode.ChildN odes.Count > 0)
{
// childs must be saved.
xClone = xDoc.XmlDoc.Cre ateElement(Node Name);
xClone.InnerTex t = Value;
foreach(XmlNode xc in xNode.ChildNode s)
xClone.AppendCh ild(xc.Clone()) ;
xParent.Replace Child(xClone, xNode);
xNode = xClone;
}
else
// no childs to save
xNode.InnerText = Value;
from .RemoveNode/.AppendChild
"Derek Harmon" <lo*******@msn. com> schrieb im Newsbeitrag
news:eV******** *****@TK2MSFTNG P14.phx.gbl... "Urs Vogel" <uv****@msn.com > wrote in message news:O$******** ******@TK2MSFTN GP14.phx.gbl... What I didn't achieve is changing the Value of a node (created with createElement), it claims that it's the wrong node type.
This is correct. Elements have no Value in the DOM. They have child nodes. Think of them as containers of other nodes, not terminal nodes.
When cloning the node and reassigning the child nodes of the original node to the cloned node,
I'd like to see the code of exactly how these reassignments are being performed before commenting on why the child nodes may not be visible in the InnerXml (if the nodes are properly moved from the original element's children to the new - cloned - element then it should work); but did you know you could also do a "deep copy" clone by passing a boolean argument of true to the CloneNode( bool) method if all you're going to do is copy the original element's children anyway.
To make it simple. How do I change the value of a node without loosing its children?
Recognize the difference between nodes and elements (Elements are nodes, but not all nodes are elements).
Then change the child nodes of the element. All an element has, besides it's identity (QName: in the Prefix, LocalName and Name- spaceUri properties), and attributes (GetAttributes( int)) -- is it's children.
Also (purely speculating), make sure if you're cloning the element and changing it, that you remember to ReplaceChild( ) the new element for the original element at the appropriate position in the document's node tree. It's not enough to merely CreateElement( ) as you must also remember to attach that element at the correct spot in its owner document.
Derek Harmon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Free-Ed, Ltd. |
last post by:
I am going nuts trying to find a paragraph in a book that described how to
change the text content (HTML) in a DIV.
Actually I have an array of HTML strings that I want to drop into the DIV,
depending on button clicks, etc.
Putting this stuff into TEXTAREA and TEXT is simple, but I want to be able
to mix font families, weights, sizes, and stuff like that.
Thanks for your help.
|
by: F. Da Costa |
last post by:
Hi,
Does anybody know why IE5+ does *not* honour array objects (like a table)
across a session?
Example:
Frame A contains a var tableVar which is set via form Frame B (on init)
using top.A.tableVar = document.getElementById("someTable");
As long as Frame B is *not* 'refreshed/ reloaded' witk another page the
|
by: Margaret MacDonald |
last post by:
I'm a js novice trying to teach myself. I'm using Flanagan's
'Javascript, the definitive guide' from O'Reilly as a text. But
either I'm dopier than usual or its layout doesn't match my learning
style very well, because I seem to be having a dreadful time getting
to grips with even the simplest things.
Currently, I'm trying to change the text that follows a <p> element in
a little test program. My test program has a table with two <td>...
|
by: Good Man |
last post by:
Hi there
I'm adding form fields on the fly with some javascript DOM programming.
I basically just clone a hidden <div>, then adjust node properties to
make this new <div> have unique values (style, size, etc.)
the original code of the input tag is:
<input type="file" onchange="alert('original')" size="30" id="filea"
name="filea">
|
by: chris yoker via DotNetMonster.com |
last post by:
hiya,
I previously obtained code that enabled me the replace a node and its
innerText.The code relied on the node that was to be replaced having
?childNodes?
However, it seems that the nodes that were empty are NOT overwritten.
So, the code is as follows:
<code>
| |
by: John N. |
last post by:
Hi All,
Here I have a linked list each containing a char and is double linked.
Then I have a pointer to an item in that list which is the current
insertion point.
In this funtion, the user hits the right
and left keys to move this insertion point (cursor)
Here is the problem:
|
by: steve |
last post by:
Hi All
I need to change text in a Report Viewer document at runtime
It is just the heading I want to change to match what the user has chosen as
the Report to view
How do I access the textbox in "GymMaster.Memberships.rdlc" (below) to
change the text
sql = "select * from members order by surname"
|
by: deepika patra |
last post by:
hi all,
i want to modify the value of a node of a xml file. i have to do this in c#.net language. i have to assume that the node value of the file wich i want to modify is already created.i shouldn't create a new file as we do using xmltextwriter class.i have to use the already existing file.also i have to read the value of modified node & have to use that value in my program.
plz suggest me how do i do that?
answer me in c#.net...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |