Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.

Posted on 2009-04-01
8
Medium Priority
?
3,550 Views
Last Modified: 2012-05-06
i am calling for an aspx page and this page generates the xml data dynamically.  I went to the browser and it is displaying results below.   Why is my dropdown menu generating error when trying to load data from my xml data?  


  <?xml version="1.0" encoding="utf-8" ?>
- <Items>
  <Item text="Black" value="2" ImageUrl="Images/black.jpg" />
  </Items>
Dim writer As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        writer.WriteStartDocument()
        writer.WriteStartElement("Items")
 
        Dim strConn2 As String = ConfigurationManager.ConnectionStrings("test").ConnectionString
        Dim conn2 As New SqlConnection(strConn2)
        conn2.Open()
 
        Dim cmd2 As New Data.SqlClient.SqlCommand("wmCGColorSP", conn2)
        cmd2.CommandType = CommandType.StoredProcedure
        cmd2.Parameters.Add("@item", SqlDbType.VarChar).Value = Request.QueryString("id")
 
        Dim dr As Data.SqlClient.SqlDataReader = Nothing
        dr = cmd2.ExecuteReader()
        While dr.Read()
            Dim description As String = String.Empty
            If ((Not dr("description") Is Nothing)) And (Not IsDBNull(dr("description"))) Then
                description = Convert.ToString(dr("description")) 'This will avoid exception if dr2("picture") is null
            End If
 
            Dim varvalue As Integer = 1
            varvalue = varvalue + 1
 
            Dim foto As String
            If description = "Blue" Then
                foto = "Images/blue.jpg"
            ElseIf description = "red" Then
                foto = "Images/Red.jpg"
            ElseIf description = "Black" Then
                foto = "Images/black.jpg"
            ElseIf description = "Orange" Then
                foto = "Images/orange.jpg"
 
            End If
 
 
 
            ' Creating the <visitInfo> element
            writer.WriteStartElement("Item")
            'writer.WriteAttributeString("timeVisited", DateTime.Now.ToString())
            writer.WriteAttributeString("text", description)
            writer.WriteAttributeString("value", varvalue)
 
            writer.WriteAttributeString("ImageUrl", foto)
       
            writer.WriteEndElement()
        End While
 
 
 
        conn2.Close()
 
        ' Response.Write(Session("xml"))
        writer.WriteEndElement()
        writer.WriteEndDocument()
        writer.Close()
    End Sub

Open in new window

0
Comment
Question by:gianitoo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 27

Expert Comment

by:nmarun
ID: 24038899
Please post the code where you are binding the xml to the dropdown menu.
0
 
LVL 1

Author Comment

by:gianitoo
ID: 24038912
    If Not Page.IsPostBack Then
            Dim combo As RadComboBox = FormView1.FindControl("RadComboBoxPaymentMethod")

            combo.LoadContentFile("~/xml.aspx")
        End If
0
 
LVL 27

Expert Comment

by:nmarun
ID: 24038933
You do realize you are loading an .aspx page right? Shouldn't that be an .xml file?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:gianitoo
ID: 24038961
yes but my aspx generates the xml.  

this is the code

<%@ Page Language="VB" ContentType="text/xml" CodeFile="xml.aspx.vb" Inherits="xml" %>

and in my code behind

Imports System.Xml
Imports System.Data.SqlClient
Imports System.Data

Partial Class xml
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim writer As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        writer.WriteStartDocument()
        writer.WriteStartElement("Items")

        Dim strConn2 As String = ConfigurationManager.ConnectionStrings("test").ConnectionString
        Dim conn2 As New SqlConnection(strConn2)
        conn2.Open()

        Dim cmd2 As New Data.SqlClient.SqlCommand("wmCGColorSP", conn2)
        cmd2.CommandType = CommandType.StoredProcedure
        cmd2.Parameters.Add("@item", SqlDbType.VarChar).Value = Request.QueryString("id")

        Dim dr As Data.SqlClient.SqlDataReader = Nothing
        dr = cmd2.ExecuteReader()
        While dr.Read()
            Dim description As String = String.Empty
            If ((Not dr("description") Is Nothing)) And (Not IsDBNull(dr("description"))) Then
                description = Convert.ToString(dr("description")) 'This will avoid exception if dr2("picture") is null
            End If

            Dim varvalue As Integer = 1
            varvalue = varvalue + 1

            Dim foto As String
            If description = "Blue" Then
                foto = "Images/blue.jpg"
            ElseIf description = "red" Then
                foto = "Images/Red.jpg"
            ElseIf description = "Black" Then
                foto = "Images/black.jpg"
            ElseIf description = "Orange" Then
                foto = "Images/orange.jpg"

            End If



            ' Creating the <visitInfo> element
            writer.WriteStartElement("Item")
            'writer.WriteAttributeString("timeVisited", DateTime.Now.ToString())
            writer.WriteAttributeString("text", description)
            writer.WriteAttributeString("value", varvalue)

            writer.WriteAttributeString("ImageUrl", foto)
       
            writer.WriteEndElement()
        End While



        conn2.Close()

        ' Response.Write(Session("xml"))
        writer.WriteEndElement()
        writer.WriteEndDocument()
        writer.Close()
    End Sub
End Class
0
 
LVL 27

Expert Comment

by:nmarun
ID: 24039010
gianitoo, That is not a good way to program. Your xml.aspx page does create the xml for you, but if you see the first line of your page:
<%@ Page ...
It is complaining about the '%' sign. You cannot remove it from the page, nor can XML work with this. So it's better you write the xml to another file.. an actual xml file.

You could try something like this:

Dim writer As New XmlTextWriter(Server.MapPath("~/data.xml"), Encoding.UTF8)
.. do the rest of the things and then do:
 combo.LoadContentFile(Server.MapPath("~/data.xml"))
0
 
LVL 1

Author Comment

by:gianitoo
ID: 24039070
How can I send my code that generates the xml data to apage called "data.xml"?
I am a little confused.  
0
 
LVL 1

Author Comment

by:gianitoo
ID: 24040290
Ok i got it .   my code below is generating an XML file called "generated.xml"
the issue is that the aspx page needs to be called in order to generate latest data in xml file.   how can i load my dropdown with latest data.  

My assumption i somehow call for aspx page before loading the dropdown???
Hoa can i accomplish it? right now it is only loading xml file.  

    If Not Page.IsPostBack Then
            Dim combo As RadComboBox = FormView1.FindControl("RadComboBoxPaymentMethod")

            combo.LoadContentFile("~/generated.xml")
        End If


xml.aspx code below
 
 
<%@ Page Language="VB"  %>
 
<%@ Import Namespace="System.Data.SqlClient" %>
 
<%@ Import Namespace="System.Data" %>
 
<%@ Import Namespace="System.Xml" %>
 
<script runat="server">
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim xmlDoc As String = Server.MapPath("generated.xml")
        Dim writer As XmlTextWriter = Nothing
        'Try
        writer = New XmlTextWriter(xmlDoc, Encoding.UTF8)
        writer.Formatting = Formatting.Indented
        writer.WriteStartDocument(True)
 
        writer.WriteComment("This file was generated from an ASPX file")
 
        writer.WriteStartElement("Items")
 
        Dim strConn2 As String = ConfigurationManager.ConnectionStrings("test").ConnectionString
        Dim conn2 As New SqlConnection(strConn2)
        conn2.Open()
 
        Dim cmd2 As New Data.SqlClient.SqlCommand("wmCGColorSP", conn2)
        cmd2.CommandType = CommandType.StoredProcedure
        cmd2.Parameters.Add("@item", SqlDbType.VarChar).Value = Request.QueryString("id")
 
        Dim dr As Data.SqlClient.SqlDataReader = Nothing
        dr = cmd2.ExecuteReader()
        While dr.Read()
            Dim description As String = String.Empty
            If ((Not dr("description") Is Nothing)) And (Not IsDBNull(dr("description"))) Then
                description = Convert.ToString(dr("description")) 'This will avoid exception if dr2("picture") is null
            End If
 
            Dim varvalue As Integer = 1
            varvalue = varvalue + 1
 
            Dim foto As String
            If description = "Blue" Then
                foto = "Images/blue.jpg"
            ElseIf description = "red" Then
                foto = "Images/Red.jpg"
            ElseIf description = "Black" Then
                foto = "Images/black.jpg"
            ElseIf description = "Orange" Then
                foto = "Images/orange.jpg"
 
            End If
 
 
            writer.WriteStartElement("Item", Nothing)
            writer.WriteAttributeString("Text", description)
            writer.WriteAttributeString("Value", varvalue)
            writer.WriteAttributeString("ImageUrl", foto)
 
            writer.WriteEndElement()
 
        End While
 
        writer.Flush()
        writer.Close()
        Dim doc As New XmlDocument()
        doc.Load(xmlDoc)
        Response.ContentType = "text/xml"
        doc.Save(Response.Output)
        'Catch
        '    Response.Write(e.ToString())
        'Finally
        '    If writer IsNot Nothing Then
        '        writer.Close()
        '    End If
        'End Try
    End Sub
</script>

Open in new window

0
 
LVL 27

Accepted Solution

by:
nmarun earned 2000 total points
ID: 24041051
You could try something like this:

mports System.Xml
Imports System.Data.SqlClient
Imports System.Data
 
Partial Class xml
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim xmlDoc As String = Server.MapPath("generated.xml")
        Dim writer As XmlTextWriter = Nothing
        writer = New XmlTextWriter(xmlDoc, Encoding.UTF8)
        writer.Formatting = Formatting.Indented
        writer.WriteStartDocument()
        writer.WriteStartElement("Items")
 
        Dim strConn2 As String = ConfigurationManager.ConnectionStrings("test").ConnectionString
        Dim conn2 As New SqlConnection(strConn2)
        conn2.Open()
 
        Dim cmd2 As New Data.SqlClient.SqlCommand("wmCGColorSP", conn2)
        cmd2.CommandType = CommandType.StoredProcedure
        cmd2.Parameters.Add("@item", SqlDbType.VarChar).Value = Request.QueryString("id")
 
        Dim dr As Data.SqlClient.SqlDataReader = Nothing
        dr = cmd2.ExecuteReader()
        While dr.Read()
            Dim description As String = String.Empty
            If ((Not dr("description") Is Nothing)) And (Not IsDBNull(dr("description"))) Then
                description = Convert.ToString(dr("description")) 'This will avoid exception if dr2("picture") is null
            End If
 
            Dim varvalue As Integer = 1
            varvalue = varvalue + 1
 
            Dim foto As String
            If description = "Blue" Then
                foto = "Images/blue.jpg"
            ElseIf description = "red" Then
                foto = "Images/Red.jpg"
            ElseIf description = "Black" Then
                foto = "Images/black.jpg"
            ElseIf description = "Orange" Then
                foto = "Images/orange.jpg"
 
            End If
 
            ' Creating the <visitInfo> element
            writer.WriteStartElement("Item")
            'writer.WriteAttributeString("timeVisited", DateTime.Now.ToString())
            writer.WriteAttributeString("text", description)
            writer.WriteAttributeString("value", varvalue)
 
            writer.WriteAttributeString("ImageUrl", foto)
       
            writer.WriteEndElement()
        End While
 
        conn2.Close()
 
        ' Response.Write(Session("xml"))
        writer.WriteEndElement()
        writer.WriteEndDocument()
        writer.Close()
        RadComboBoxPaymentMethod.LoadContentFile("generated.xml")
 
    End Sub
End Class

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question