NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 79 80 81 82 83 … 93 Next »
deleting an xml node

 
  • 0 Vote(s) - 0 Average
deleting an xml node
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#1
2005-01-13, 01:30 PM
im trying to delete a node, eg "/a/b/c/d" ie deleting the d child.

ive tried using
doc.RemoveChild(doc.SelectSingleNode("/a/b/c/d&quotWink) //error not achild
then tried:
XmlNode node = doc.SelectSingleNode("/a/b/c&quotWink)
node.RemoveChild(node.SelectSingleNode("/d&quotWink) //error not a child

so ive had to use
XmlNode baseNode = doc.SelectSingleNode("/a/b/c&quotWink;
foreach(XmlNode node in baseNode.ChildNodes){
if(node.Name == "d&quotWink
baseNode.RemoveChild(node);
}
which works, but its not the best way to do things, slower, and i want to know what my stupid mistake is. anyone see it?



KingArgyle
Offline

Posting Freak

Posts: 1,271
Threads: 95
Joined: Nov 2004
#2
2005-01-13, 03:03 PM
Try something like:

Node root = inDocument.getElementsByTagName("client&quotWink.item(0);
root.parentNode.removeChild(root);
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#3
2005-01-13, 03:14 PM
ok the document has the getelementsbytagname method, which i assuem returns every tag that matchs the name as an array, i have mutliple instances of the "pin" tag (the one im trying to delete, just one of them). xmlfile is like so
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><DirView>
<ELEMENT>
<ROOT/>
<PIN/>
<ELEMENT>
<ROOT/>
<PIN/>
</ELEMENT>
</DIRVIEWS>
[/QUOTE]
so each element has pin and a root, and also can have subelements, so if use doc.getelementsbytagname(&quot;PIN&quotWink = returns array, how do i know which position in the array i want, dont tell me its as easy as doing getelementsbyname(&quot;\DIRVIEW\ELEMENT\PIN&quotWink, cause i doubt its that.
KingArgyle
Offline

Posting Freak

Posts: 1,271
Threads: 95
Joined: Nov 2004
#4
2005-01-13, 03:23 PM
Node root = doc.SelectSingleNode(&quot;/a/b/c/d&quotWink;
root.ParentNode.removeChild(root);

That should get you what you want. Haven't tested this, but should work.

I believe your original problem was because you were trying to remove the node you had found from the Document level, instead of going back, to the parent node, and then removing it. Which is why when you get a list of all the nodes, and then identified the one you wanted, you were able to remove it, (You were at it's parent). You have to remove from the parent level.



reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#5
2005-01-13, 03:59 PM
yup that did the trick, cheers KingArgyle, again [Image: smile.gif]
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected result when deleting a pending recording scJohn 5 3,630 2018-05-06, 10:09 PM
Last Post: sub
  API access to artwork and deleting recordings cncb 29 15,371 2016-11-06, 02:20 AM
Last Post: mvallevand
  Delayed deleting mvallevand 2 2,742 2015-03-09, 06:30 PM
Last Post: sub
  Recorder plugins - Deleting tuners mvallevand 1 1,489 2012-03-29, 12:51 AM
Last Post: sub
  The node to be inserted is from a different document context imilne 7 4,330 2012-01-30, 08:36 AM
Last Post: bgowland

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode