473,406 Members | 2,698 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,406 software developers and data experts.

xmlNode.RemoveChild is removing xmlNode...not the child node

WebDunce
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...and i cant figure out why!

any ideas?

thanks in advance.
Mar 14 '07 #1
5 7786
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.InnerXml is displaying the node i think i am selecting plus all siblings

nodeToRemove.OuterXml 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 SelectSingleNode select the single node?)
thanks.
Mar 14 '07 #2
kenobewan
4,871 Expert 4TB
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
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 SelectSingleNode method at all...like i originally thought.

turns out...SelectSingleNode 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)...but at least now i know what is wrong and my confidence is restored in the SelectSingleNode 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
ahem..."hardcard" = "hardcode" oops!
Mar 14 '07 #5
kenobewan
4,871 Expert 4TB
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
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 =...
1
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...
2
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
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.,...
0
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.,...
2
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...
0
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...
1
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
isladogs
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...

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.