> 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>XML</MainCategory>
> <Description>This is a list my XML
> articles.</Description>
> <Active>true</Active>
> </Category>
> </CategoryList>
>
> Code:
>
> XmlDocument xmlDoc = new XmlDocument();
> xmlDoc.Load(Server.MapPath("categories.xml"));
>
> XmlNode node = xmlDoc.SelectSingleNode
> ("/CategoryList/Category[@ID='01']");
> XmlNode commonParent = node.ParentNode;
>
> if(node != null)
> {
> commonParent.RemoveChild(node);
> }
>
> xmlDoc.Save(Server.MapPath("categories.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?
> >
> >
> >
> ><Advertisements>
> >
> ><Ad>
> >
> ><ImageUrl>http://localhost/UQCN/Images/Ecoroute.gif</Image
> Url>
> >
> ><NavigateUrl>/UQCN/WebModules/AdsManager/PassThrough.aspx?
> 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>http://localhost/UQCN/Images/foretboreale.jpg</I
> mageUrl>
> >
> ><NavigateUrl>/UQCN/WebModules/AdsManager/PassThrough.aspx?
> 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.aspx?
> 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.PassThroughPage & "?AD=" & _
> >
> >advertisementId.ToString() & """]"
> >
> >rotatorDom.Load(rotatorFile)
> >
> >
> >
> >Dim currentAd As XmlNode = _
> >
> >CType(rotatorDom.DocumentElement.SelectSingleNode
> (xPathFind), XmlNode)
> >
> >rotatorDom.DocumentElement.RemoveChild(currentAd)
> >
> >
> >
> >My file still jam with this element!!!! Nothing changes
> >
> >
> >
> >
> >.
> >