473,696 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10502
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_P LEASEtkachenko. com> wrote in message
news:eJ******** ******@TK2MSFTN GP12.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.Document Element.ChildNo des

If xmlnode.Attribu tes("Name").Val ue = "TEST2" Then
xmldoc.Document Element.RemoveC hild(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******@onlin e.microsoft.com > wrote in message
news:H4******** ******@cpmsftng xa06.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.Document Element.ChildNo des

If xmlnode.Attribu tes("Name").Val ue = "TEST2" Then
xmldoc.Document Element.RemoveC hild(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>Tru e</Location>

thanks for your help
Gerry
"MSFT" <lu******@onlin e.microsoft.com > wrote in message
news:H4******** ******@cpmsftng xa06.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.Document Element.ChildNo des

If xmlnode.Attribu tes("Name").Val ue = "TEST2" Then
xmldoc.Document Element.RemoveC hild(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_P LEASEtkachenko. com> wrote in message
news:Od******** ******@TK2MSFTN GP12.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.e du> wrote in message
news:%2******** ********@TK2MSF TNGP11.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_P LEASEtkachenko. com> wrote in message
news:Od******** ******@TK2MSFTN GP12.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
3082
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:TMSWebServices"> All attributes are removed EXCEPT
2
1595
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 and its length, that can impact the performance of an XML parser? The bulk of our XML parsing uses the latest and greatest version of Apache Xerces.
1
4106
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" attribute2="value2" ... /> ...
6
2586
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 schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
2
2119
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" xsi:schemaLocation="urn:/ows/aws/1.2 http://www.overture.com/schema/dtc/1.2/dtc_response.xsd" xmlns="urn:/ows/aws/1.2" success="true"> <ActionsResponse accountId="123"> <GetAccountIdsResponse success="true"> <Account id="123" market="UK" /> ....
3
10830
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 server tables programmatically. The web service builds and deploys with no problems. When I try to add the corresponding Web Reference to the Web Site project I get the error listed below. I am able to create other Web Services on the same server...
14
2027
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 is in. I want to avoid making the user have to submit the form's id if possible. Let me know if my question is unclear...thanks! Kel
2
1964
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 attribute xml:lang="EN" in some elements which should not be there. I am enclosing the code for reference. I used to remove the occurences manually...but now I need an assembly which can do that for me in C#.I have to remove the occurences of the word...
2
6588
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' attr2='somevalue' attrN='...'>markup</span>" 3 Dim objSpan As HTMLSpanElement = browser.Document.createElement("span") 4 objSpan.innerHTML = strMarkup
0
8592
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
9005
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8871
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
7694
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...
1
6512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
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
4605
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1989
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.