Click to See Complete Forum and Search --> : Asp.Net And XML


gorkemsez
02-23-2009, 03:14 AM
Hi guys;

I have a problem. I wrote xml content below. My xml file's name is Schedule1.xml

<?xml version="1.0" encoding="UTF-8" ?>
<SCHEDULE>
<PROGRAM>
<SDATE>2008-02-02</SDATE>
<EDATE>2008-02-02</EDATE>
<ADVERT_LIST>
<ADVERT>
<STARTHOUR>10:00</STARTHOUR>
<ENDHOUR>12:00</ENDHOUR>
<TYPE>PICTURE</TYPE>
<SUBTITLE_LOCATION>HTTP</SUBTITLE_LOCATION>
<SUBTITLE_SOURCE>http://84.44.51.154/Text/a.txt</SUBTITLE_SOURCE>
<CONTENT_LIST>
<CONTENT>http://84.44.51.154/Image/1.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Catching.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Lotus.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Fairyland.jpg</CONTENT>
</CONTENT_LIST>
</ADVERT>
<ADVERT>
<STARTHOUR>14:00</STARTHOUR>
<ENDHOUR>16:00</ENDHOUR>
<TYPE>VIDEO</TYPE>
<SUBTITLE_LOCATION>HTTP</SUBTITLE_LOCATION>
<SUBTITLE_SOURCE>http://84.44.51.154/Text/b.txt</SUBTITLE_SOURCE>
<CONTENT_LIST>
<CONTENT>http://84.44.51.154/Video/Afrikason.mpg</CONTENT>
<CONTENT>http://84.44.51.154/Video/dansozmantikli.mpg</CONTENT>
<CONTENT></CONTENT>
<CONTENT></CONTENT>
</CONTENT_LIST>
</ADVERT>
</ADVERT_LIST>
</PROGRAM>
<PROGRAM>
<SDATE>2008-02-03</SDATE>
<EDATE>2008-02-03</EDATE>
<ADVERT_LIST>
<ADVERT>
<STARTHOUR>09:00</STARTHOUR>
<ENDHOUR>11:00</ENDHOUR>
<TYPE>VIDEO</TYPE>
<SUBTITLE_LOCATION>HTTP</SUBTITLE_LOCATION>
<SUBTITLE_SOURCE>http://84.44.51.154/Text/c.txt</SUBTITLE_SOURCE>
<CONTENT_LIST>
<CONTENT>http://84.44.51.154/Video/Afrikason.mpg</CONTENT>
<CONTENT>http://84.44.51.154/Video/dansozmantikli.mpg</CONTENT>
<CONTENT></CONTENT>
<CONTENT></CONTENT>
</CONTENT_LIST>
</ADVERT>
<ADVERT>
<STARTHOUR>13:00</STARTHOUR>
<ENDHOUR>15:00</ENDHOUR>
<TYPE>PICTURE</TYPE>
<SUBTITLE_LOCATION>HTTP</SUBTITLE_LOCATION>
<SUBTITLE_SOURCE>http://84.44.51.154/Text/d.txt</SUBTITLE_SOURCE>
<CONTENT_LIST>
<CONTENT>http://84.44.51.154/Image/1.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Catching.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Lotus.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Fairyland.jpg</CONTENT>
</CONTENT_LIST>
</ADVERT>
</ADVERT_LIST>
</PROGRAM>
<PROGRAM>
<SDATE>2008-02-04</SDATE>
<EDATE>2008-02-04</EDATE>
<ADVERT_LIST>
<ADVERT>
<STARTHOUR>10:00</STARTHOUR>
<ENDHOUR>12:00</ENDHOUR>
<TYPE>PICTURE</TYPE>
<SUBTITLE_LOCATION>HTTP</SUBTITLE_LOCATION>
<SUBTITLE_SOURCE>http://84.44.51.154/Text/a.txt</SUBTITLE_SOURCE>
<CONTENT_LIST>
<CONTENT>http://84.44.51.154/Image/1.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Catching.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Lotus.jpg</CONTENT>
<CONTENT>http://84.44.51.154/Image/Fairyland.jpg</CONTENT>
</CONTENT_LIST>
</ADVERT>
<ADVERT>
<STARTHOUR>14:00</STARTHOUR>
<ENDHOUR>16:00</ENDHOUR>
<TYPE>VIDEO</TYPE>
<SUBTITLE_LOCATION>HTTP</SUBTITLE_LOCATION>
<SUBTITLE_SOURCE>http://84.44.51.154/Text/b.txt</SUBTITLE_SOURCE>
<CONTENT_LIST>
<CONTENT>http://84.44.51.154/Video/Afrikason.mpg</CONTENT>
<CONTENT>http://84.44.51.154/Video/dansozmantikli.mpg</CONTENT>
<CONTENT></CONTENT>
<CONTENT></CONTENT>
</CONTENT_LIST>
</ADVERT>
</ADVERT_LIST>
</PROGRAM>
</SCHEDULE>
----------------------------------------
And below asp.net-vb.net code:

Imports System.Xml
Imports System.Data
Imports System.Xml.XPath
Partial Class Default13

Inherits System.Web.UI.Page
Dim url As String = Server.MapPath("Schedule1.xml")
Dim DS As New DataSet
Public Function Search1(ByVal szKeywords As String) As String
'Dimension your variables
Dim Results As String
Dim objDoc As New XmlDocument()
Dim intNodes As Integer = 0
Dim szResults As String
Dim objNode As XmlNode
objDoc.Load(Server.MapPath("Schedule1.xml"))
'objDoc.Load(Server.MapPath("Schedule2.xml"))
Dim objNodesCount As XmlNodeList
Dim objNodeCount As XmlNode
'objNodesCount = objDoc.SelectNodes("SCHEDULE/PROGRAM")
objNodesCount = objDoc.SelectNodes("SCHEDULE/PROGRAM/ADVERT_LIST")
Dim j As Integer = 0
For Each objNodeCount In objNodesCount
j += 1
Next

Dim l As Integer = 1
Dim objNodes2 As XmlNodeList

objNodes2 = objDoc.SelectNodes("SCHEDULE/PROGRAM/ADVERT_LIST/ADVERT[" & 0 & "][*[contains(translate(text(),'abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'),translate('" & szKeywords & "','abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'))]]/*[2] | SCHEDULE/PROGRAM/ADVERT_LIST[" & 1 & "][*[contains(translate(text(),'abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'),translate('" & szKeywords & "','abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'))]]/*[1] | SCHEDULE/PROGRAM/ADVERT_LIST[" & 1 & "][*[contains(translate(text(),'abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'),translate('" & szKeywords & "','abcdefghijklmnopqrstuvxyz','ABCDEFGHIJKLMNOPQRSTUVXYZ'))]]/*[3]")
For Each objNode In objNodes2
Select Case objNode.Name
Case "DATE"
Results += "<b><font color='#000066'>Başlangıç Tarihi</font></b>" & ": <a href=" & Chr(34) & "details.aspx?title=" & objNode.SelectSingleNode("text()").Value & "&keyword=" & szKeywords & Chr(34) & ">" & objNode.SelectSingleNode("text()").Value & "</a><br>"
Case "STARTHOUR"
Results += " <b><font color='#000066'>Başlangıç Saati</font></b>" & ": " & objNode.SelectSingleNode("text()").Value & "<br>"
Case "ENDHOUR"
Results += " <b><font color='#000066'>Bitiş Saati</font></b>" & ": " & objNode.SelectSingleNode("text()").Value & "<br>"
Case "TYPE"
Results += " <b><font color='#000066'>Tip</font></b>" & ": " & objNode.SelectSingleNode("text()").Value & "<br>"
Case "SUBTITLE_LOCATION"
Results += "<b><font color='#000066'>Alt Yazı Lokasyonu</font></b>" & ": " & objNode.SelectSingleNode("text()").Value & "<br>"
Case "SUBTITLE_SOURCE"
Results += " <b><font color='#000066'>Alt Yazı Kaynağı</font></b>" & ": " & objNode.SelectSingleNode("text()").Value & "<br>"
Case "CONTENT_LIST"
Results += " <b><font color='#000066'>İçerik1</font></b>" & ": " & objNode.SelectSingleNode("text()").Value & "<br>"

End Select
intNodes = intNodes + 1
Next
l += 1
intNodes /= 2
szResults = "<h3>Sonuçlar:</h3>"
If intNodes = 0 Then
Results = "Bu tarihle ilgili bilgi mevcut değil<b>'" & szKeywords & "'</b><br>"
Else
Results = szResults & Results
End If
Results = Results & "<hr>"
Results = Regex.Replace(Results, "(?i: \b(" & szKeywords & ")\b)", " <span style='background-color:00ffff;'>$1</span>")
Return Results
End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Label1.Text = Search1(DropDownList1.SelectedItem.Text)
Label1.Visible = True
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
DS.ReadXml(url)
DropDownList1.DataSource = DS.Tables(0)
DropDownList1.DataValueField = DS.Tables(0).Columns(0).ToString()
DropDownList1.DataBind()
End Sub
End Class

-------------------------------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default13.aspx.vb" Inherits="Default13" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
</asp:DropDownList>&nbsp;<asp:Button ID="Button1" runat="server" Text="Tarihleri Oku" /><br />
<br />
<asp:Label ID="Label1" runat="server" Visible="False"></asp:Label></div>
</form>
</body>
</html>
----------------------------------
My purpose; SDATE tag in xml file is appearing on dropdownlist1.Later I will select date from dropdownlist.And then xml content must be appeared in label by date. Please can u help me?

chazzy
02-23-2009, 07:11 AM
so you want to take the XML document, make changes, and then save it using VB.NET? is that correct?

gorkemsez
02-23-2009, 07:34 AM
so you want to take the XML document, make changes, and then save it using VB.NET? is that correct?

read xml.and then ı will select date from dropdownlist1. It will search date and then will appear in table or listbox information related to date.