SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    ireland
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing, Replacing nodes in xml

    How do you Remove/Delete and Replace a node in an xml file. I know how to append to an xml file http://www.dmsproperty.co.uk/Code/AppendXml.asp
    Any help would be appreciated

    V.

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Vender
    How do you Remove/Delete and Replace a node in an xml file. I know how to append to an xml file http://www.dmsproperty.co.uk/Code/AppendXml.asp
    Any help would be appreciated

    V.
    Hope this helps.
    Code:
    'removeAll method
    Set oSelection = xmlDoc.selectNodes("//book")
    oSelection.removeAll
    Response.Write xmlDoc.xml
     
    'removeAttribute method, IXMLDOMElement
    Set nodeBook = xmlDoc.selectSingleNode("//book")
    Response.Write nodeBook.Attributes.length
    nodeBook.removeAttribute "id"
    Response.Write nodeBook.Attributes.length
     
    'removeAttributeNode method
    Set nodeBook = xmlDoc.selectSingleNode("//book")
    Set nodeId = nodeBook.getAttributeNode("id")
    Response.Write nodeBook.Attributes.length
    nodeBook.removeAttributeNode nodeId
    Response.Write nodeBook.Attributes.length
     
    'removeChild method
    Set root = xmlDoc.documentElement
    Set currNode = root.childNodes.Item(1)
    Set oldChild = currNode.removeChild(currNode.childNodes.Item(1))
    Response.Write oldChild.Text
     
    'removeNamedItem method
    Set nodeBook = xmlDoc.selectSingleNode("//book")
    Response.Write nodeBook.Attributes.length
    nodeBook.Attributes.removeNamedItem "id"
    Response.Write nodeBook.Attributes.length
     
    'removeNext method
    Set oSelection = xmlDoc.selectNodes("//book")
    While Not (oSelection.peekNode() Is Nothing)
    	oSelection.removeNext
    Wend
    Response.Write xmlDoc.xml
     
    'removeQualifiedItem method
    Set nodeBook = xmlDoc.selectSingleNode("//book")
    Response.Write nodeBook.Attributes.length
    nodeBook.Attributes.removeQualifiedItem "id", ""
     
    'replaceChild method
    Set root = xmlDoc.documentElement
    Set newElem = xmlDoc.createElement("PAGES")
    root.childNodes.Item(1).replaceChild newElem, root.childNodes.Item(1).childNodes.Item(0)
    Response.Write root.childNodes.Item(1).xml
     
    'replaceData method
    Set comment = xmlDoc.createComment("Hello World!")
    Response.Write comment.xml
    comment.replaceData 0, 5, "Goodbye, Cruel"
    Response.Write comment.xml


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
  •