Question : Need help in creating XML file

Hello, I'm creating an xml file that needs to look like this:

http://www.google.com/schemas/sitemap/0.84">
 
  http://www.webica.net/Solution Architecture - An Ideal design._1_316.aspx
  2007-05-05od>
  weeklyfreq>
  0.6
 




Mine looks like this:


 
    http://localhost:49317/RCS/Review.aspx?ReviewId=84D7D6A4-6F4E-4E49-834C-F78FCCD6F57D
    Jan 11 2010
    weekelyefreq>
    0.6
 



The URL portion looks fine but these lines are the ones I need help with:


http://www.google.com/schemas/sitemap/0.84">


This is a console app
 Attached is my code:


Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text

Public Class Site
    Dim objConn As SqlConnection = New SqlConnection("Data Source=localhost;Initial Catalog=xxx;User ID=xxx;Password=xxx")

    Public Function GoogleSiteMap() As DataSet
        Dim dsSiteMapData As New DataSet("SiteMapData")
        Dim errorMessages As New StringBuilder()

        Try
            Dim objCmd As SqlCommand = New SqlCommand("Get_SiteMapData", objConn)
            objCmd.CommandType = CommandType.StoredProcedure

            objConn.Open()

            objCmd.ExecuteNonQuery()

            Dim objDA As New SqlDataAdapter(objCmd)

            objDA.Fill(dsSiteMapData, "url")

        Catch ex As SqlException
            Dim i As Integer
            For i = 0 To ex.Errors.Count - 1
                errorMessages.Append("Index #" & i.ToString() & ControlChars.NewLine _
                    & "Message: " & ex.Errors(i).Message & ControlChars.NewLine _
                    & "LineNumber: " & ex.Errors(i).LineNumber & ControlChars.NewLine _
                    & "Source: " & ex.Errors(i).Source & ControlChars.NewLine _
                    & "Procedure: " & ex.Errors(i).Procedure & ControlChars.NewLine)
            Next i
            Console.WriteLine(errorMessages.ToString())

        Finally
            objConn.Close()
        End Try

        Return dsSiteMapData

    End Function
End Class
End Module




Module Module1

    Sub Main()
        Dim s As New Site()
        s.GoogleSiteMap.WriteXml(System.IO.Path.GetFullPath("SiteMap.xml"), XmlWriteMode.IgnoreSchema)
    End Sub

End Module

Answer : Need help in creating XML file

You can change the root element name just by renaming the dataset (to "urlset"), although that won't give you the namespace declaration.

If you want fine control over your output, don't use WriteXml.

Use GetXml, convert it into an Xml tree, and then you can make the appropriate changes before writing it out to disk.
Random Solutions  
 
programming4us programming4us