Thanks for this post. I have tried it out and it works a treat. So I can use
document. The problem I had was that althought I could cycle through the
xmlreader. It doesent seem possible.
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:u5gJVFbLHHA.320@TK2MSFTNGP06.phx.gbl...
> Just Me wrote:
>> Does anyone have code or can point to usefull snippets to allow me to
>> traverse the xml "Elements" of an xmlDocument.
>>
>> What I want to do is to move through the entire document and when I hit
>> <table> <tr> <td> clear the attributes for these Elements and also
>> remove all Elelments NOT nested inside a <table>
>
> If you use System.Xml.XmlDocument and SelectNodes then you have a powerful
> tool to select the nodes you are looking for, then you can use the DOM
> methods to remove nodes. Example to remove all attributes on table, tr,
> and td elements is like this
>
> Dim XmlDoc As XmlDocument = New XmlDocument
> XmlDoc.Load("XMLFile1.xml")
> Console.WriteLine("Initial Document:")
> XmlDoc.Save(Console.Out)
> Console.WriteLine()
> Dim AttributesToRemove As XmlNodeList = _
> XmlDoc.SelectNodes("//table/@* | //tr/@* | //td/@*")
> For I As Integer = AttributesToRemove.Count - 1 To 0 Step -1
> Dim Attribute As XmlAttribute = _
> CType(AttributesToRemove(I), XmlAttribute)
> Attribute.OwnerElement.RemoveAttributeNode(Attribute)
> Next
>
> Console.WriteLine("Changed document:")
> XmlDoc.Save(Console.Out)
>
> Example output:
>
> Initial Document:
> <?xml version="1.0" encoding="ibm850"?>
> <html lang="en">
> <head>
> <title>Example</title>
> </head>
> <body>
> <table border="1" class="some-class" id="t1">
> <tbody>
> <tr class="odd">
> <td id="cell1">
> </td>
> </tr>
> </tbody>
> </table>
> </body>
> </html>
> Changed document:
> <?xml version="1.0" encoding="ibm850"?>
> <html lang="en">
> <head>
> <title>Example</title>
> </head>
> <body>
> <table>
> <tbody>
> <tr>
> <td>
> </td>
> </tr>
> </tbody>
> </table>
> </body>
> </html>
>
> An XPath expression to select all elements inside of the document body
> that are not nested in a table is e.g.
> /html/body//*[not(ancestor-or-self::table)]
>
>
> --
>
> Martin Honnen --- MVP XML
>
http://JavaScript.FAQTs.com/