473,594 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing XML Element. Simple??? Give me your trick please

This is my XML file and below you will find my code to remove it... I was
thinking that it's a simple task but this code doesn't work.

Anybody have a better solution?

<Advertisements >

<Ad>

<ImageUrl>htt p://localhost/UQCN/Images/Ecoroute.gif</ImageUrl>

<NavigateUrl>/UQCN/WebModules/AdsManager/PassThrough.asp x?AD=4</NavigateUrl>

<AlternateText> Test!</AlternateText>

<Keyword>Wrox </Keyword>

<Impressions> 1</Impressions>

</Ad>

----------Here is the element I want to remove from my XML doc

<Ad>

<ImageUrl>htt p://localhost/UQCN/Images/foretboreale.jp g</ImageUrl>

<NavigateUrl>/UQCN/WebModules/AdsManager/PassThrough.asp x?AD=5</NavigateUrl>

<AlternateText> Test 2</AlternateText>

<Keyword>Wrox 2</Keyword>

<Impressions> 5</Impressions>

</Ad>

---------------------------------------End of removed
element--------------------------------

<Ad>

<ImageUrl>htt p://localhost/UQCN/Images/Aptitudes.jpg</ImageUrl>

<NavigateUrl>/UQCN/WebModules/AdsManager/PassThrough.asp x?AD=6</NavigateUrl>

<AlternateText> tytvytv</AlternateText>

<Keyword>1</Keyword>

<Impressions> 1</Impressions>

</Ad>

</Advertisements>

Here is my Code

Dim rotatorDom As New XmlDocument()

rotatorDom.Load (rotatorFile)

Dim xPathFind As String = "//Ad[NavigateUrl=""" & _

settings.PassTh roughPage & "?AD=" & _

advertisementId .ToString() & """]"

rotatorDom.Load (rotatorFile)

Dim currentAd As XmlNode = _

CType(rotatorDo m.DocumentEleme nt.SelectSingle Node(xPathFind) , XmlNode)

rotatorDom.Docu mentElement.Rem oveChild(curren tAd)

My file still jam with this element!!!! Nothing changes


Nov 12 '05 #1
2 4595
I might be wrong but the caller of RemoveChild must be his
parent. I created a small example to demonstrate this:

XML:

<?xml version="1.0" encoding="utf-8"?>
<CategoryList >
<Category ID="01">
<MainCategory>X ML</MainCategory>
<Description>Th is is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
</CategoryList>

Code:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Ser ver.MapPath("ca tegories.xml")) ;

XmlNode node = xmlDoc.SelectSi ngleNode
("/CategoryList/Category[@ID='01']");
XmlNode commonParent = node.ParentNode ;

if(node != null)
{
commonParent.Re moveChild(node) ;
}

xmlDoc.Save(Ser ver.MapPath("ca tegories.xml")) ;
hth

Sonu Kapoor
http://weblogs.asp.net/sonukapoor/
-----Original Message-----
This is my XML file and below you will find my code to remove it... I wasthinking that it's a simple task but this code doesn't work.
Anybody have a better solution?

<Advertisement s>

<Ad>

<ImageUrl>http ://localhost/UQCN/Images/Ecoroute.gif</Image Url>
<NavigateUrl >/UQCN/WebModules/AdsManager/PassThrough.asp x? AD=4</NavigateUrl>
<AlternateText >Test!</AlternateText>

<Keyword>Wro x</Keyword>

<Impressions>1 </Impressions>

</Ad>

----------Here is the element I want to remove from my XML doc
<Ad>

<ImageUrl>http ://localhost/UQCN/Images/foretboreale.jp g</I mageUrl>
<NavigateUrl >/UQCN/WebModules/AdsManager/PassThrough.asp x? AD=5</NavigateUrl>
<AlternateText >Test 2</AlternateText>

<Keyword>Wrox2 </Keyword>

<Impressions>5 </Impressions>

</Ad>

---------------------------------------End of removed
element--------------------------------

<Ad>

<ImageUrl>http ://localhost/UQCN/Images/Aptitudes.jpg</Imag eUrl>
<NavigateUrl >/UQCN/WebModules/AdsManager/PassThrough.asp x? AD=6</NavigateUrl>
<AlternateText >tytvytv</AlternateText>

<Keyword>1</Keyword>

<Impressions>1 </Impressions>

</Ad>

</Advertisements>

Here is my Code

Dim rotatorDom As New XmlDocument()

rotatorDom.Loa d(rotatorFile)

Dim xPathFind As String = "//Ad[NavigateUrl=""" & _

settings.PassT hroughPage & "?AD=" & _

advertisementI d.ToString() & """]"

rotatorDom.Loa d(rotatorFile)

Dim currentAd As XmlNode = _

CType(rotatorD om.DocumentElem ent.SelectSingl eNode (xPathFind), XmlNode)
rotatorDom.Doc umentElement.Re moveChild(curre ntAd)

My file still jam with this element!!!! Nothing changes


.

Nov 12 '05 #2
Well tks buddy,
My code is good except that didn't save my change after updating my file
All I needed is
xmlDoc.Save(Ser ver.MapPath("ca tegories.xml")) ;

Tks again

"Sonu Kapoor" <vi*****@hotmai l.com> a écrit dans le message de
news:10******** *************** ******@phx.gbl. ..
I might be wrong but the caller of RemoveChild must be his
parent. I created a small example to demonstrate this:

XML:

<?xml version="1.0" encoding="utf-8"?>
<CategoryList >
<Category ID="01">
<MainCategory>X ML</MainCategory>
<Description>Th is is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
</CategoryList>

Code:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Ser ver.MapPath("ca tegories.xml")) ;

XmlNode node = xmlDoc.SelectSi ngleNode
("/CategoryList/Category[@ID='01']");
XmlNode commonParent = node.ParentNode ;

if(node != null)
{
commonParent.Re moveChild(node) ;
}

xmlDoc.Save(Ser ver.MapPath("ca tegories.xml")) ;
hth

Sonu Kapoor
http://weblogs.asp.net/sonukapoor/
-----Original Message-----
This is my XML file and below you will find my code to

remove it... I was
thinking that it's a simple task but this code doesn't

work.

Anybody have a better solution?

<Advertisement s>

<Ad>

<ImageUrl>http ://localhost/UQCN/Images/Ecoroute.gif</Image

Url>

<NavigateUrl >/UQCN/WebModules/AdsManager/PassThrough.asp x?

AD=4</NavigateUrl>

<AlternateText >Test!</AlternateText>

<Keyword>Wro x</Keyword>

<Impressions>1 </Impressions>

</Ad>

----------Here is the element I want to remove from my

XML doc

<Ad>

<ImageUrl>http ://localhost/UQCN/Images/foretboreale.jp g</I

mageUrl>

<NavigateUrl >/UQCN/WebModules/AdsManager/PassThrough.asp x?

AD=5</NavigateUrl>

<AlternateText >Test 2</AlternateText>

<Keyword>Wrox2 </Keyword>

<Impressions>5 </Impressions>

</Ad>

---------------------------------------End of removed
element--------------------------------

<Ad>

<ImageUrl>http ://localhost/UQCN/Images/Aptitudes.jpg</Imag

eUrl>

<NavigateUrl >/UQCN/WebModules/AdsManager/PassThrough.asp x?

AD=6</NavigateUrl>

<AlternateText >tytvytv</AlternateText>

<Keyword>1</Keyword>

<Impressions>1 </Impressions>

</Ad>

</Advertisements>

Here is my Code

Dim rotatorDom As New XmlDocument()

rotatorDom.Loa d(rotatorFile)

Dim xPathFind As String = "//Ad[NavigateUrl=""" & _

settings.PassT hroughPage & "?AD=" & _

advertisementI d.ToString() & """]"

rotatorDom.Loa d(rotatorFile)

Dim currentAd As XmlNode = _

CType(rotatorD om.DocumentElem ent.SelectSingl eNode

(xPathFind), XmlNode)

rotatorDom.Doc umentElement.Re moveChild(curre ntAd)

My file still jam with this element!!!! Nothing changes


.

Nov 12 '05 #3

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

Similar topics

2
1428
by: Graham | last post by:
Hi all, I'm trying to clean up the output from Word that has been pasted into a textarea. I'm purging much of the html (all styles, attributes etc) and would also like to remove things like vector graphics. To do this I want to simply drop all elements (or their children) which are in any namespace other than the default: all the microsoft-specific o:p, v:drawLine, etc tags. But I can't persuade javascript to even see the namespaces!...
6
2142
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. could you please have a look at the following script: ------------------------------------------------------------
2
1532
by: bmgz | last post by:
I have written a simple function that validates a form based on the form objects' className attribute. The form basically write a "field required" message next to the form element that is blank(and is required). I have implemented all the Regex stuff onload already. function checkRequired(varForm){ var varReturn = true; for(var i=0; i<varForm.length; i++){ if(varForm.elements.className.indexOf('required') != -1 &&\...
2
10681
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this attribute and remove the containing node (and child nodes) if it has a certain value. I'm able to find the attributes using an XmlTextReader. Once found, can someone help me get the XPath at that point? I would then use this to remove the node from...
3
4702
by: kevin | last post by:
Is that even possible? I am creating a web service in .NET to expose some already created .NET programs to other groups. One group is writing the client in PERL, and thus wishes the wsdl schema to not be sequenced. (PERL hashes do not retain order information) First, the w3 specs don't mention the sequence in any detail - its just there in the examples, which makes me wonder if removing the sequence tag is even supportable. Second,...
24
4364
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
7
2970
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a xmlns present is because the Xml I am passing to CRM is a node from a bigger file that does require a xmlns and using the DOM ..OuterXml seems to set the xmlns for you automatically - which I don't want. Any help would be great.
2
2259
by: Daz | last post by:
Hi everyone. Is it possible to remove a script that has been added to a page? I have asked this question before, and was told that it was pretty much impossible to do, unless of course, I deleted the function. I have had a little think, and I might have stumbled upon a method of achieving this, without having to know what functions you actually want to delete. It might be a method already in practise, so I doubt it's original, which is...
5
2286
by: fleemo17 | last post by:
Over the course of building a very large site, I've wound up with an enormous style sheet containing plenty of superfluous styles. Is there a tool that can recognize which styles are not being used in a site and eliminate them? Can Dreamweaver perform that function?
0
7947
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8255
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8242
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
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
3868
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
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1217
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.