SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Removing all nodes based on attribute

    Hi
    New to these forums, hope you can help, my XML programming experience is minimal so still struggling with some of the concepts and best approaches.

    I have an XMLdocument which has many child nodes.
    There is an attribute on some nodes, "Deleted".

    I need to parse my XMLDocument
    I want to remove all nodes and children which have this "Deleted" attribute.
    Cannot show code example, forum wont let me as new member

    Any help appreciated, thanks

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2009
    Location
    Bavaria, Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It'd be helpful if you tell us, what programming language should do the thing you want to do.

    If you want to do that in PHP, search for DomDocument or another XML parser, shouldn't be that difficult to identifiy tags with a specified attribute.

    Any other language should have an analog way of identifiying tags/attributes/whateveryoulike...

  3. #3
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would have helped, sorry.
    It was in VB.NET
    I eventually, through trial and error, worked out how to do it. Probably not the most efficient way but it worked.

    Code:
    bMore = true
    do
    
    oNode = oDocClone.DocumentElement.SelectSingleNode("//*[@Deleted='1']")
      if not IsNothing(oNode) then
          oNode.ParentNode.RemoveChild(oNode)
      else
         bMore = False
      end if
    loop while bMore
    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •