473,662 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xmlNode.RemoveC hild is removing xmlNode...not the child node

WebDunce
15 New Member
Hi guys,

I am trying to develop a simple xml editor. I have an object that has a TreeView. I use the TreeView to display the Xml node info. That's all fine, but i want the user to be able to move the actual xml nodes about by interacting with the non-xml TreeView nodes.

my basic algorithm is as follows:
  • user has selected a treeview node
  • if user presses Ctrl+Up Arrow, then
    • clone the corresponding xml node
    • remove the xml node
    • insert the xml node CLONE into the parent xml
      node's child list BEFORE the node that was
      above the node to start with

the treeview nodes are working just right...but to my dismay, when remove the selected xml node...the parent also disappears!

basically, I am doing this...

Expand|Select|Wrap|Line Numbers
  1. Dim nodeToRemove As XmlNode =  Me.xmlDoc.SelectSingleNode("//page[@id=/website/@currentPageId]")
  2. Dim parentNode As XmlNode = nodeToRemove.ParentNode
  3. parentNode.RemoveChild(nodeToRemove)
  4.  
this is removing parentNode...an d i cant figure out why!

any ideas?

thanks in advance.
Mar 14 '07 #1
5 7815
WebDunce
15 New Member
okay...a little more research produces some insight...

Expand|Select|Wrap|Line Numbers
  1. 'xmlDoc is an XmlDocument object
  2.  
  3.  Dim nodeToRemove As XmlNode = Me.xmlDoc.SelectSingleNode("//page[@id=/website/@currentPageId]")
  4.  Dim parentNode As XmlNode = nodeToRemove.ParentNode
  5.  'parentNode.RemoveChild(nodeToRemove)
  6.  MainForm.TextBox1.Text = nodeToRemove.InnerXml
  7.  
nodeToRemove.In nerXml is displaying the node i think i am selecting plus all siblings

nodeToRemove.Ou terXml is displaying what i would consider to be the parent node.

what am i missing here...how can i select a single node (why doesn't SelectSingleNod e select the single node?)
thanks.
Mar 14 '07 #2
kenobewan
4,871 Recognized Expert Specialist
I believe that you need to reference the child node in the remove, something like:
Expand|Select|Wrap|Line Numbers
  1. XmlNode.RemoveChild(XmlNode.SelectSingleNode("ChildNode"))
Mar 14 '07 #3
WebDunce
15 New Member
hi KenObeWan,

i appreciate the response, but i think i tried every which way to reference the node...all with the same results. however, i think i found the problem...and it wasn't with the SelectSingleNod e method at all...like i originally thought.

turns out...SelectSin gleNode is working just like it should (surprise, surprise, surprise)...i just wasn't feeding it the info i THOUGHT i was giving it...

turns out my code (somewhere) is not updating the attribute value (/website/@currentPageId) like i am thinking it is...

when i reference that attribute value like so:
Expand|Select|Wrap|Line Numbers
  1. nodeToRemove = Me.xmlDoc.SelectSingleNode("//page[@id=/website/@currentPageId]")
  2.  
i get the parent node not the node i am wanting...

but when i hardcard the page id value like so:
Expand|Select|Wrap|Line Numbers
  1. nodeToRemove = Me.xmlDoc.SelectSingleNode("//page[@id='0018']")
  2.  
then it works...i get the node i am expecting.

now to find out why the attribute value is not updating like i thought i told it to...(sigh)...b ut at least now i know what is wrong and my confidence is restored in the SelectSingleNod e method.

thanks for letting me post...even if it turned out i simply answered myself...:) sometimes it helps just to write the problem out. And posting it publicly encourages me to try even harder to come up with a solution, too.

cheers all.
Mar 14 '07 #4
WebDunce
15 New Member
ahem..."hardcar d" = "hardcode" oops!
Mar 14 '07 #5
kenobewan
4,871 Recognized Expert Specialist
Well done - shows that you are no dunce ;). Thanks for sharing the solution.
Mar 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3688
by: JehanNYNJ | last post by:
I need to clear out the HTML contents of a <span> element and then re-add that element as a blank span. Here is the code... var elem = document.getElementById(spanId); var deletedElem = elem.parentNode.removeChild(elem); deletedElem.innerHTML = '<span id="'+spanId+'"></span>'; deletedElem.parentNode.appendChild(deletedElem);
1
3161
by: ason | last post by:
Hi, I just tried to replace a single XmlNode with several ChildNodes. When doing this with the following code i found out that if you get the ChildNodes with 'ChildNodes' - property the nodes get removed. Is this possibly a Framework Bug?? foreach( XmlNode node in oldNode.ChildNodes ) {
2
5384
by: Sam | last post by:
I am attempting to remove a full node. XML Example: <Videos> <Video> <Name>Crocodile Dundee 2</Name> <Media>DVD</Media> </Video> <Video> <Name>Terminator 6</Name> <Media>DVD</Media>
1
4943
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg., <Root> <mysection>
0
1701
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg., <Root> <mysection>
2
1575
by: Pete | last post by:
Hi All, I have a div that contains several elements. I want to remove the div from the page. At the moment I am using removeChild to remove the div from the page. As good practice should I be removing the child nodes within the div before i remove the main div? Cheers, Pete
0
2396
by: sakurasyi | last post by:
hi there... i really need your help.. i develop a calendar event using java. all event that i insert will be saved into xml file. But, i have problem when trying to remove the event that i saved. Can somebody tell me how to remove elements in xml file? this is my xml file:- <?xml version="1.0" encoding="UTF-8"?> <Calendars> <events><eventID>E012</eventID><date>01012006</date><event>my birthday...now i'm 24...</event></events>...
1
10717
by: Rebecca Tsukalas | last post by:
Hello, I have a problem concerning removeChild. This is the XML structure I use with php: <xml_thing <language1 <site>bla1</site <site>bla2</site <site>bla3</site </language1
5
8518
by: Christof Nordiek | last post by:
When I load a XML-Document from a file, and then get an XmlNode from it, is there any way to get the its original position in the file (line, character)? I want to report it, when there is something odd about that node, so that a user can find the position in the file. Similar to the errormessage from XmlDocument.Load, if the file isn't wellformed XML. If that's not possible, would it be possible when examining the XML with other...
0
8343
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,...
0
8856
Oralloy
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...
1
8545
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,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
agi2029
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...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.