Det du skal gøre er at loade dit xml dokument, og lave en XPath query for at finde den node du gerne vil slette og på rootnoden i dit xml dokument kalde .removeChild(xmlnode);
Hej Thomas
Fandt egentligt ud af det er lettere at læse xml filen ind i et dataset
og manipulere med data'ene der istedet for
men fandt da ud af hel del om XPath query og xml
håber det lykkedes og få eksemlet her foldet .
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml.Xpath" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="vb" Debug="true" CodeBehind="search1.aspx.vb" AutoEventWireup="false" Inherits="nauticom.search1" %>
<HTML>
<HEAD>
<script runat="server">
Public Function Search(ByVal szKeywords As String) As String
'Dimension your variables
Dim Results As String
Dim objDoc As New XmlDocument()
Dim intNodes as Integer = 0
Dim objEntry As XmlNode
Dim objEntryItems As XmlNodeList
Dim szResults As String
Dim intEntries As Integer
Dim objNode As XmlNode
'Enumerate number of total entries in the database
objDoc.Load(Server.MapPath("db.xml"))
Dim objNodesCount As XmlNodeList
Dim objNodeCount As XmlNode
'Select all of the entries in the database and load them into a XMLNodeList
objNodesCount = objDoc.SelectNodes("root/entry")
Dim j As Integer = 0
'For every entry in the DB, increment the J variable by one.
For Each objNodeCount In objNodesCount
j += 1
Next
'Select nodes that have the keyword in its value
Dim l As Integer = 1
Dim objNodes As XmlNodeList
'Recall: j = the number of entries
Do While l <= j
'The XPATH statement returns the 1st (Title in this case) and the 2nd (Author in this case) node of an entry that has a node whose value contains the keyword.
objNodes = objDoc.SelectNodes("/root/entry[" & l & "][*[contains(translate(text(),'abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'),translate('" & szKeywords & "','abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'))]]/*[1] | /root/entry[" & l & "][*[contains(translate(text(),'abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'),translate('" & szKeywords & "','abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'))]]/*[2]")
For Each objNode In objNodes
Select Case objNode.Name
'Print out the results of the XPATH query and make the title a link.
Case "Title"
Results += "<b><font color='#000066'>Title</font></b>" & ": <a href=" & Chr(34) & "details.aspx?title=" & objNode.SelectSingleNode("text()").Value & "&keyword=" & szKeywords & Chr(34) & ">" & objNode.SelectSingleNode("text()").Value & "</a>"
Case "Author"
Results += "<b><font color='#000066'>Date</font></b>" & ": " & objNode.SelectSingleNode("text()").Value & ""
End Select
'Increment intNodes. intNodes will be used to determine how many results there are.
intNodes = intNodes + 1
Next
l += 1
Loop
'Divide by two because intNodes holds the number of nodes that matched but there are two nodes per entry
'i.e. Title and Author make up one entry.
intNodes /= 2
szResults = "<h3>Results:</h3><hr>"
'Check for results
If intNodes = 0 Then
Results = "No items matching <b>'" & szKeywords & "'</b>"
Else
Results = szResults & Results
End If
Results = Results & "<hr> Found " & intNodes & " results."
'When the function is called, return the variable Results which holds all of the HTML of the search results.
results = regex.Replace(results, "(?i: \\b(" & szKeywords & ")\\b)", " <span style='background-color:00ffff;'>$1</span>")
Return Results
End Function
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
lblResults.Text = Search(txtKeywords.Text)
End Sub
</script>
</HEAD>
<body>
<form runat="server" method="post" id="Form1">
<img src="logo.gif">
This example shows you how to search XML data using XPATH. Then
using regular epressions, the keyword is highlighted.
Code by <a href="mailto:mattpociask@email.com">Matt Pociask</a>
This code can be used by anyone at anytime; just please, if you like it, vote
for me.
<span style='COLOR:#003366'>Enter keywords:</span>
<asp:textbox id="txtKeywords" runat="server"></asp:textbox>
<asp:button id="cmdGo" runat="server" text="Start Search" onClick="cmdGo_Click"></asp:button>
<asp:label id="lblResults" runat="server" />
</form>
</body>
</HTML>
Jens
[Redigeret d. 11/08-05 00:03:46 af Nauticom]