Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removeChilld 1

Status
Not open for further replies.

hererxnl

Technical User
Jul 8, 2003
239
US
I'm trying to use classic ASP to delete the first child's child.

Here's the the XML example (XSPF PL):

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version="1" xmlns="[URL unfurl="true"]http://xspf.org/ns/0/">[/URL]
    <title>Playlist</title>
    <info>Whatever</info>
    <trackList>
        <track>
            <annotation>Me - You</annotation>
            <location>../Me/You.Mp3</location>
            <image>../Me/You.jpg</image>
        </track>
        <track>
            <annotation>You - Me</annotation>
            <location>../You/Me.Mp3</location>
            <image>../You/Me.jpg</image>
        </track>
    </trackList>
</playlist>

Here's the ASP code I'm using:

Code:
Dim objXML
Dim objXMLTracks
Dim objXMLTrack
Dim objRoot
Dim objNode

Set objXML = Server.CreateObject("MSXML2.DomDocument.3.0")
objXML.async = False
objXML.load (Server.MapPath("playlists/Playlist.xml"))
'Collect All Tracks From Playlist
Set objXMLTracks = objXML.getElementsByTagName("track")
'Select First Track
Set objXMLTrack = objXMLTracks.Item(0)
Set objRoot = objXML.documentElement
Set objNode = objRoot.SelectSingleNode("trackList[track/annotation='" & objXMLTrack.firstChild.text & "']")
objRoot.removeChild(objNode)
Set objNode = Nothing
Set objRoot = Nothing
Set objXMLTrack = Nothing
Set objXMLTracks = Nothing
'Save The Edited Playlist
objXML.save (Server.MapPath("playlists/Playlist.xml"))
Set objXML = Nothing

Anyone who understand the DOM tree will probably already know this is deleting all tracks from my playlist, instead of the first one.

Would someone be so kind as to help me out or better yet give me a more efficient way to accomplish this?

Here's the article I've been using:

Thanks In Advance
 
It seems there are unnecessary entanglements flipping between native dom method and xpath. You can simply do this.
[tt]
Dim objXML
Dim objXMLTracks
Dim objXMLTrack
Dim objRoot
Dim objNode

Set objXML = Server.CreateObject("MSXML2.DomDocument.3.0")
objXML.async = False
objXML.load (Server.MapPath("playlists/Playlist.xml"))
'Collect All Tracks From Playlist
Set objXMLTracks = objXML.getElementsByTagName("track")
'Select First Track
Set objXMLTrack = objXMLTracks.Item(0)
[blue]objXMLTrack.parentNode.removeChild objXMLTrack[/blue]
[green]'take them all out[/green]
[red]'[/red]Set objRoot = objXML.documentElement
[red]'[/red]Set objNode = objRoot.SelectSingleNode("trackList[track/annotation='" & objXMLTrack.firstChild.text & "']")
[red]'[/red]objRoot.removeChild(objNode)
[red]'[/red]Set objNode = Nothing
[red]'[/red]Set objRoot = Nothing
Set objXMLTrack = Nothing
Set objXMLTracks = Nothing
'Save The Edited Playlist
objXML.save (Server.MapPath("playlists/Playlist.xml"))
Set objXML = Nothing
[/tt]
 

Thanks tsuji. I knew it should be more simple.

A star for your efforts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top