Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2007, 08:10 AM
Registered User
 
Join Date: Dec 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Writing XML file Using XmlTextWriter class

Hi....................

Am working with ASP.NET Usin VB for a Music Project...

I have the list of songs for a movie in a datagrid with a checkbox.If check box is checked then that song shoul play when PlaySelected button is clicked.

Here the player is taking the xml file i.e when we click on the PlaySelected button a xml file should created...

like

<playlist>

<element url="skins/skin1/songs/Movie/Aata/aata.mp3" />

<element url="'/>

</playlist>

I have the following code....

Private Sub playSelected()
Dim check As Boolean

Dim Music As New MusicMachine
Dim strname As String = Music.GetMusicFileId

Dim item As DataGridItemDim writer As New XmlTextWriter(Server.MapPath("~\XML\") & strname & ".xml", Encoding.UTF8)
writer.WriteStartDocument()

writer.WriteStartElement("playlist")

Try

For Each item In FileSystemGrid.Items Dim chkBx As CheckBox = CType(item.Cells(0).FindControl("deletethis"), CheckBox)
If chkBx.Checked Then

check = True

writer.WriteElementString("element", "")

writer.WriteAttributeString("url", "Skins\skin1\Songs\" & Request.QueryString("Type") & "\" & Request.QueryString("Name") & "\" & item.Cells(2).Text)

Page.RegisterStartupScript("Popup", "<script> popUp('player.aspx');</script>")

End If

Next

If check = False Then

Response.Write("<script language=""javascript"">alert('Select at least One Song!');</script>")

End If

writer.WriteEndElement()

writer.WriteEndDocument()

writer.Close()

Catch ex As Exception
Response.Write(ex.Message)

Response.End()

End Try

End Sub



................................

But the above code is not working,It is displaying a error like

Token StartAttribute in state Content would result in an invalid XML document.



Please help me out

Thanks in Advance


 
Old December 19th, 2007, 09:20 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Once the call the WriteElementString has completed you are not in the element tag anymore, so you are adding the attribute to nothing.

Just do a WriteStartElement("element") before the WriteAttributeString() and then a WriteEndElement() after it.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
writing into xml file jerryjohn XML 1 August 18th, 2006 02:40 AM
XML and the XMLTextWriter AgentSmith General .NET 1 May 10th, 2006 07:42 PM
writing to am xml file MOU Classic ASP XML 0 July 6th, 2005 07:38 AM
Writing XML file within Loop (c#) rathbird General .NET 0 December 13th, 2004 05:26 PM
over writing an xml file using asp jojys XML 2 September 14th, 2004 08:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.