473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Replacing a node

Hi all:

Is there a way to replace a node and it's children? I tried using the
ReplaceChild method but that seems to only replace the first child only!!

Thanks
Ed;;
Nov 12 '05 #1
3 1304


Ed A wrote:
Is there a way to replace a node and it's children? I tried using the
ReplaceChild method but that seems to only replace the first child only!!


node.ParentNode.ReplaceChild(newNode, node)
will replace node with newNode.

If you still have problems then provide more details on what you have tried.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

This is what I've tried:

My XML file looks like this
......
<Collection name="DbTestCollection1" TopLeftX="-86.4037416919"
TopLeftY="20.63144694" BottomRightX="-86.3945403259"
BottomRightY="20.626370603" DefaultFloor="1">
<Layers PATH="C:\Program Files\Maps">
<Layer IMAGE="DB_map.tif" BASE="true" />
<Layer IMAGE="FloorPlan2.tif" BASE="false" BUILDING="1" FLOOR="1" />
</Layers>
<Buildings>
<Building number="1" CN="Building_1" />
</Buildings>
<Floors>
<Floor number="1" CN="Floor_1" BuildingNumber="1" />
</Floors>
<Columns>
<Column number="0" CN="Column A" BuildingNumber="1" />
</Columns>
</Collection>
......
I look for my local node in the file first then I create a new one from the
databse to replace it:

// Look for the node name in the collections file
XmlNode localNode = FindNode(_name,xmlDoc);

// now I create the new node
// Collection name
collectionNode = _xmlDoc.CreateNode(XmlNodeType.Element,"Collection ","");

// Collection Name
XmlAttribute attr = _xmlDoc.CreateAttribute("name");
attr.Value = map.Name;
collectionNode.Attributes.Append(attr);
.....
....
....

// Then I call replace node
localNode.ParentNode.ReplaceChild(collectionNode,l ocalNode);

this seems to only replace the
<Collection name=........></Collection>
tag and non of its children.
Thanks
Ed;;

"Martin Honnen" wrote:


Ed A wrote:
Is there a way to replace a node and it's children? I tried using the
ReplaceChild method but that seems to only replace the first child only!!


node.ParentNode.ReplaceChild(newNode, node)
will replace node with newNode.

If you still have problems then provide more details on what you have tried.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #3
Hello!
XmlNode localNode = FindNode(_name,xmlDoc);

// now I create the new node
// Collection name
collectionNode = _xmlDoc.CreateNode(XmlNodeType.Element,"Collection ","");


This looks as if you would be using two different XmlDocument-s xmlDoc
and _xmlDoc. This doesn't work.
To use "foreign" nodes from an other XmlDocument, you first have to
import them using XmlDocument.ImportNode:
<http://msdn2.microsoft.com/en-us/library/System.Xml.XmlDocument.ImportNode>

So, add the line

xmlDoc.ImportNode( collectionNode, /*Deep*/true );
--
Pascal Schmitt
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: anonymous | last post by:
Hello, I need to replace this char  with another char. However I am not able to acieve this. I tried this but it doesnt work: str = str.Replace(chr(asc(194)), "") Can somebody help ?
4
by: miroslaw.rusin | last post by:
Hi mates! :) The challange is like this: how to replace only one element in the whole tree to something else? Example: Input: <?xml version="1.0"?> <html>
1
by: dotnetnoob | last post by:
i need to copy several xml files and use it as xml element and insert them into a xml file. i use DOM support in .Net and from the pervious help i was able to copy and insert them into the xml file...
32
by: FireHead | last post by:
Hello C World & Fanatics I am trying replace fgets and provide a equavivalant function of BufferedInputReader::readLine. I am calling this readLine function as get_Stream. In the line 4 where...
0
by: theFLY | last post by:
Hello there, I have an XML file of structure that looks like this: <?xml version="1.0"?> <documents> <header id="1"> <title></title> <prodGroup></prodGroup> <version> ...
0
by: theFLY | last post by:
This has posted in the ASP sub-forum, to no avail I re-post here. Hello there, I have an XML file of structure that looks like this: <?xml version="1.0"?> <documents> <header...
13
by: jtric | last post by:
Very new to XML/XSL, so please forgive me if this is an incredibly simple question. I've been pulling my hair out over this for several days now. I'm working on an internal application that takes...
1
by: patelgaurav85 | last post by:
Hi, I want to convert xml in one format into another xml format shown below Input xml : <Name> <Name1> <Name11>Name11</Name11> <Name12>Name12</Name12>
1
by: TamusJRoyce | last post by:
I have xsl code which I was hoping could be used to replace one specific tag from an xhtml document and output another xhtml document. xsl has phenomenal potential in data replacing, but coming...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.