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

Remove Element and Attributes

Hi all,

The following is part of XML file, how do I search through the file and remove an
Element and all it's attributes. Example: TEST2? Of course I will pass the Element Name to remove
from a control.

- <Forms>
- <Form Name="TEST1">
<Width>600</Width>
<Height>400</Height>
<Tag>2-1</Tag>
</Form>
<Form Name="TEST2">
<Width>200</Width>
<Height>26</Height>
<Tag>2-3</Tag>
</Form>
<Form Name="TEST3">
<Width>300</Width>
<Height>45</Height>
<Tag>2-4</Tag>
</Form>
</Forms>

To look like this?

<Forms>
- <Form Name="TEST1">
<Width>600</Width>
<Height>400</Height>
<Tag>2-1</Tag>
</Form>
<Form Name="TEST3">
<Width>300</Width>
<Height>45</Height>
<Tag>2-4</Tag>
</Form>
</Forms>

Thanks
Gerry
Nov 11 '05 #1
8 10472
Gerry Viator wrote:
The following is part of XML file, how do I search through the file and
remove an
Element and all it's attributes. Example: TEST2? Of course I will pass
the Element Name to remove
from a control.


DOM solution - load document into XmlDocument, locate the element and
remove it.
XSLT solution - identity transfomation + custom template for Form element.
XmlReader solution - read till the element, skip till EndElement and
continue.
Which one do you prefer?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
DOM solution - load document into XmlDocument, locate the element and
remove it

This would be fine. Thanks

Gerry
"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Gerry Viator wrote:
The following is part of XML file, how do I search through the file and
remove an
Element and all it's attributes. Example: TEST2? Of course I will pass
the Element Name to remove
from a control.


DOM solution - load document into XmlDocument, locate the element and
remove it.
XSLT solution - identity transfomation + custom template for Form element.
XmlReader solution - read till the element, skip till EndElement and
continue.
Which one do you prefer?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
Thank for Oleg's Idea. I attach some sample code as the supply to his post:

Dim xmldoc As New XmlDocument

xmldoc.Load("c:\edit1.xml")

Dim xmlnode As XmlNode

For Each xmlnode In xmldoc.DocumentElement.ChildNodes

If xmlnode.Attributes("Name").Value = "TEST2" Then
xmldoc.DocumentElement.RemoveChild(xmlnode)

End If
Next

xmldoc.Save("c:\edit2.xml")

Gerry, Hope this answer your question.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #4
Thanks everyone,

Gerry

"MSFT" <lu******@online.microsoft.com> wrote in message
news:H4**************@cpmsftngxa06.phx.gbl...
Thank for Oleg's Idea. I attach some sample code as the supply to his post:
Dim xmldoc As New XmlDocument

xmldoc.Load("c:\edit1.xml")

Dim xmlnode As XmlNode

For Each xmlnode In xmldoc.DocumentElement.ChildNodes

If xmlnode.Attributes("Name").Value = "TEST2" Then
xmldoc.DocumentElement.RemoveChild(xmlnode)

End If
Next

xmldoc.Save("c:\edit2.xml")

Gerry, Hope this answer your question.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #5
Thanks again,

What if I wanted to change the value below of TEST2?

<Width>300</Width>

to 350?

and add this to TEST2?

<Location>True</Location>

thanks for your help
Gerry
"MSFT" <lu******@online.microsoft.com> wrote in message
news:H4**************@cpmsftngxa06.phx.gbl...
Thank for Oleg's Idea. I attach some sample code as the supply to his post:
Dim xmldoc As New XmlDocument

xmldoc.Load("c:\edit1.xml")

Dim xmlnode As XmlNode

For Each xmlnode In xmldoc.DocumentElement.ChildNodes

If xmlnode.Attributes("Name").Value = "TEST2" Then
xmldoc.DocumentElement.RemoveChild(xmlnode)

End If
Next

xmldoc.Save("c:\edit2.xml")

Gerry, Hope this answer your question.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #6
Gerry Viator wrote:
What if I wanted to change the value below of TEST2?

<Width>300</Width>

to 350?

and add this to TEST2?


Gerry, to avoid asking such simple questions learn about using XmlDocument
class, e.g.
"Modifying Nodes, Content, and Values in an XML Document" [1]
"Inserting Nodes into an XML Document" [2]
"Select Nodes Using XPath Navigation" [3]

[1]
http://msdn.microsoft.com/library/en...mldocument.asp
[2]
http://msdn.microsoft.com/library/en...mldocument.asp
[3]
http://msdn.microsoft.com/library/en...navigation.asp
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #7
Thanks for links,

I also wish Microsoft would make there HELP much better then it is.
On line and within VS.NET. I always search first, but get
frustrated with not findings what I'm looking for.

Microsofts Help can be made alot better. I do beleive they are going to make
major changes to it from what I hear.

Thanks
Gerry

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Gerry Viator wrote:
What if I wanted to change the value below of TEST2?

<Width>300</Width>

to 350?

and add this to TEST2?
Gerry, to avoid asking such simple questions learn about using XmlDocument
class, e.g.
"Modifying Nodes, Content, and Values in an XML Document" [1]
"Inserting Nodes into an XML Document" [2]
"Select Nodes Using XPath Navigation" [3]

[1]

http://msdn.microsoft.com/library/en...mldocument.asp [2]
http://msdn.microsoft.com/library/en...mldocument.asp [3]
http://msdn.microsoft.com/library/en...navigation.asp --
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #8
Ice
This stuff should be in the framework sdk.

ice
"Gerry Viator" <vi*****@musc.edu> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thanks for links,

I also wish Microsoft would make there HELP much better then it is.
On line and within VS.NET. I always search first, but get
frustrated with not findings what I'm looking for.

Microsofts Help can be made alot better. I do beleive they are going to make major changes to it from what I hear.

Thanks
Gerry

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Gerry Viator wrote:
What if I wanted to change the value below of TEST2?

<Width>300</Width>

to 350?

and add this to TEST2?


Gerry, to avoid asking such simple questions learn about using XmlDocument class, e.g.
"Modifying Nodes, Content, and Values in an XML Document" [1]
"Inserting Nodes into an XML Document" [2]
"Select Nodes Using XPath Navigation" [3]

[1]

http://msdn.microsoft.com/library/en...mldocument.asp
[2]

http://msdn.microsoft.com/library/en...mldocument.asp
[3]

http://msdn.microsoft.com/library/en...navigation.asp
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel


Nov 11 '05 #9

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

Similar topics

3
by: sam.stamport | last post by:
Hello, In my C# program I execute an attributes remove to remove all attributes in the following root node. <xtvd xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
2
by: Tom Kerigan | last post by:
I know that longer element names increase the size of an XML document, ultimately resulting in a larger amount of data at parse-time. Is there anything else, specifically related to an element name...
1
by: Tod Johnson | last post by:
Hello all, Can't figure it out. :( Assume that we have 2 XML document: Document1 (source): <elements> <elementA attribute1="value1" attribute2="value2" ... /> <elementA attribute1="value1"...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
2
by: fizzy | last post by:
i am fetching an xml document with the following structure: <?xml version="1.0" encoding="UTF-8"?> <DTCResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
3
by: namewitheldbyrequest | last post by:
"The XML element 'EnableTheming' from namespace 'http://tempuri.org/' is already present in the current scope" I created a Web Service: I imported System.Data.SqlClient so I could access SQL...
14
by: kelvin.jones | last post by:
Hi, if I had the ID of an input element, how can I find the input's FORM in javascript? Basically, given a input's dom id, I want to insert something in the onSubmit of the Form that that input...
2
by: kasala | last post by:
I get an xml document as input from other department. The input xml document i recieve has a particular word "rnx" which should not be there and my system doesn't support it. And there is also...
2
by: cloftis | last post by:
Using VS2003, VB and MSHTML, Using an HTMLSpanElement I want to enumerate the attributes of a SPAN tag. 1 'For testing sake 2 Dim strMarkup as String = "<span attr1='somevalue'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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?
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...

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.