473,387 Members | 1,757 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,387 software developers and data experts.

XML Delete

I have just started working with XML , and am sure this is easy but
drawing blanks on this one!

e.g
<Files>
<File>C:\File1.txt</File>
<File>C:\File2.txt</File>
<File>C:\File3.txt</File>
</Files>
How do i remove the element <File>C:\File2.txt</File>
Thanks
Colin Williams

May 10 '07 #1
3 3697


Each <Fileis a child of <Files>

http://msdn2.microsoft.com/en-us/lib...movechild.aspx

You use an xpath to get a hold of the <FilesNode.
XmlNode parentN = // some .SelectSingleNode method here

You use xpath to get a hold of the specific <FileNode.
XmlNode childN = // some .SelectSingleNode method here

and then call

parentN.RemoveChild(childN);

See the url above.



"Colin Williams" <co**************@msn.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
I have just started working with XML , and am sure this is easy but
drawing blanks on this one!

e.g
<Files>
<File>C:\File1.txt</File>
<File>C:\File2.txt</File>
<File>C:\File3.txt</File>
</Files>
How do i remove the element <File>C:\File2.txt</File>
Thanks
Colin Williams

May 10 '07 #2
Colin Williams wrote:
I have just started working with XML , and am sure this is easy but
drawing blanks on this one!

e.g
<Files>
<File>C:\File1.txt</File>
<File>C:\File2.txt</File>
<File>C:\File3.txt</File>
</Files>
How do i remove the element <File>C:\File2.txt</File>
Use System.Xml.XmlDocument e.g. as in
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"file.xml");
XmlNode file =
xmlDoc.SelectSingleNode(@"Files/File[. = 'C:\File2.txt']");
if (file != null) {
file.ParentNode.RemoveChild(file);
xmlDoc.Save(@"file.xml");
}
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 11 '07 #3
You're right.

I forgot about the:
file.ParentNode.RemoveChild(file);

trick.


"Martin Honnen" <ma*******@yahoo.dewrote in message
news:ui**************@TK2MSFTNGP06.phx.gbl...
Colin Williams wrote:
I have just started working with XML , and am sure this is easy but
drawing blanks on this one!

e.g
<Files>
<File>C:\File1.txt</File>
<File>C:\File2.txt</File>
<File>C:\File3.txt</File>
</Files>
How do i remove the element <File>C:\File2.txt</File>

Use System.Xml.XmlDocument e.g. as in
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"file.xml");
XmlNode file =
xmlDoc.SelectSingleNode(@"Files/File[. = 'C:\File2.txt']");
if (file != null) {
file.ParentNode.RemoveChild(file);
xmlDoc.Save(@"file.xml");
}
--

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

May 15 '07 #4

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

Similar topics

2
by: Dave | last post by:
Hello all, In the code below, I see the following output: base::operator new(size_t, int) base::base() base::~base() base::operator delete(void *) In the case of an exception being thrown...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
2
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new...
3
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >>...
9
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
10
by: jeffjohnson_alpha | last post by:
We all know that a new-expression, foo* a = new foo() ; allocates memory for a single foo then calls foo::foo(). And we know that void* p = ::operator new(sizeof(foo)) ; allocates a...
15
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
29
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.