Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. I have a problem with streaming XML.

I have a problem with streaming XML.

Scheduled Pinned Locked Moved ASP.NET
helpsysadmindata-structuresdebuggingxml
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zoltix
    wrote on last edited by
    #1

    Hi, I have a problem with streaming XML. I have created an aspx which return me an xml file format (Type text/xml, Encoding.UTF8). Also now, I try to read this stream in the XmlTextReader but I receive an Error Message when I parse it. And of course, I don't understand that. Could you help me? It is a bit urgent.... Thanks a lot Code Source XmlTextReader XR = new XmlTextReader(Server.MapPath("GenerateXmlTreeView.aspx")); while(!XR.EOF){ XR.ReadElementString(); //Here Thrown exception } Sr.Close(); When I run may aspx Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Xml.XmlException: The '%' character, hexadecimal value 0x25, cannot begin a name. Line 1, position 2. Source Error: Source XML:

    J R 2 Replies Last reply
    0
    • Z zoltix

      Hi, I have a problem with streaming XML. I have created an aspx which return me an xml file format (Type text/xml, Encoding.UTF8). Also now, I try to read this stream in the XmlTextReader but I receive an Error Message when I parse it. And of course, I don't understand that. Could you help me? It is a bit urgent.... Thanks a lot Code Source XmlTextReader XR = new XmlTextReader(Server.MapPath("GenerateXmlTreeView.aspx")); while(!XR.EOF){ XR.ReadElementString(); //Here Thrown exception } Sr.Close(); When I run may aspx Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Xml.XmlException: The '%' character, hexadecimal value 0x25, cannot begin a name. Line 1, position 2. Source Error: Source XML:

      J Offline
      J Offline
      John Honan
      wrote on last edited by
      #2

      It can't be a coincidence that the second character of a raw .aspx page is '%' ... <%@ Page Language="vb" ... Looks to me like first line is being included in the stream, instead of pure XML. Try streaming that page to a string first to see if it gives what you're expecting. John.

      Z 1 Reply Last reply
      0
      • J John Honan

        It can't be a coincidence that the second character of a raw .aspx page is '%' ... <%@ Page Language="vb" ... Looks to me like first line is being included in the stream, instead of pure XML. Try streaming that page to a string first to see if it gives what you're expecting. John.

        Z Offline
        Z Offline
        zoltix
        wrote on last edited by
        #3

        When I open the link(GenerateXml.aspx) in my explorer, I have a good xml. I think that my method to open my xml is not good. Do you know a other method for making that? or how to get the output of that page into another page? -=zoltx=-

        J 1 Reply Last reply
        0
        • Z zoltix

          When I open the link(GenerateXml.aspx) in my explorer, I have a good xml. I think that my method to open my xml is not good. Do you know a other method for making that? or how to get the output of that page into another page? -=zoltx=-

          J Offline
          J Offline
          John Honan
          wrote on last edited by
          #4

          Why are you reading in the GenerateXmlTreeView.aspx file using XmlTextReader? - I would assume (since you haven't posted the code for GenerateXmlTreeView.aspx), that this page reads an XML file, and formats it into a treeview. At this point, you should just be able to include it directly in your page. (i.e. no need for a XmlTextReader, as the page is already parsed into HTML) John. www.silveronion.com[^]

          Z 1 Reply Last reply
          0
          • J John Honan

            Why are you reading in the GenerateXmlTreeView.aspx file using XmlTextReader? - I would assume (since you haven't posted the code for GenerateXmlTreeView.aspx), that this page reads an XML file, and formats it into a treeview. At this point, you should just be able to include it directly in your page. (i.e. no need for a XmlTextReader, as the page is already parsed into HTML) John. www.silveronion.com[^]

            Z Offline
            Z Offline
            zoltix
            wrote on last edited by
            #5

            Yes, I know, but I would like to parse this xml for other things. For example fill in a ListBox or other Controls. I hope that it is possible. Perhaps, I chose bad method for making that. Also, if you know a other method, thank you in advance Ps: GenerateXmlTreeView.aspx is on distant webserver. -=zoltx=-

            Z 1 Reply Last reply
            0
            • Z zoltix

              Yes, I know, but I would like to parse this xml for other things. For example fill in a ListBox or other Controls. I hope that it is possible. Perhaps, I chose bad method for making that. Also, if you know a other method, thank you in advance Ps: GenerateXmlTreeView.aspx is on distant webserver. -=zoltx=-

              Z Offline
              Z Offline
              zoltix
              wrote on last edited by
              #6

              Source, a part of GenerateTreeXml.aspx XmlTextWriter tw = new XmlTextWriter(Response.OutputStream,Encoding.UTF8);//,Encoding.UTF8 //XmlTextWriter tw = new XmlTextWriter(s); Response.Clear(); Response.Expires=0; Response.ContentEncoding = Encoding.UTF8; Response.ContentType="text/xml"; tw.Formatting=Formatting.Indented; tw.WriteStartDocument(); tw.WriteStartElement("treeview"); tw.WriteAttributeString("title","Licenses Tool"); tw.WriteStartElement("custom-parameters"); tw.WriteStartElement("param"); tw.WriteAttributeString("name","shift-width"); tw.WriteAttributeString("value","15"); tw.WriteEndElement(); tw.WriteStartElement("param"); tw.WriteAttributeString("name","img-directory"); tw.WriteAttributeString("value","images/"); tw.WriteEndElement(); tw.WriteEndElement(); int level=0; string IdElement=""; Level.add(""); string Name=""; string IdPrduit=""; string IdParent=""; string License=""; string PrevIdParent=""; string PrevIdElement=""; bool FlagElementFirst= true ; foreach(DataRow r in DT.Rows) { if (FlagElementFirst == true) { Level.Remove(0); Level.add(r["idSetParent"].ToString()); } IdElement = r["idSet"].ToString(); Name = r["setName"].ToString(); IdPrduit = r["idProduct"].ToString(); IdParent = r["idSetParent"].ToString(); License = r["license"].ToString(); if(( Level[IdParent]>=level ||level==0 )) { if((IdParent=="" || IdParent!=PrevIdParent ) && (IdPrduit=="") ) { Console.WriteLine("Name"); tw.WriteStartElement("folder"); tw.WriteAttributeString("title",Name); if (FlagElementFirst == true) { tw.WriteAttributeString("url",IdElement); } else { tw.WriteAttributeString("url",IdElement); } level++ ; Level.add(IdElement); PrevIdParent=IdParent; PrevIdElement =IdElement; } else if((IdParent==PrevIdParent)&& IdParent!="" && (IdPrduit=="") ) { tw.WriteStartElement("folder"); tw.WriteAttributeString("title",Name); tw.WriteAttributeString("url",IdElement); Level.add(IdElement); PrevIdParent=IdParent; PrevIdElement =IdElement; level++; } else if(IdPrduit!="")

              J 1 Reply Last reply
              0
              • Z zoltix

                Source, a part of GenerateTreeXml.aspx XmlTextWriter tw = new XmlTextWriter(Response.OutputStream,Encoding.UTF8);//,Encoding.UTF8 //XmlTextWriter tw = new XmlTextWriter(s); Response.Clear(); Response.Expires=0; Response.ContentEncoding = Encoding.UTF8; Response.ContentType="text/xml"; tw.Formatting=Formatting.Indented; tw.WriteStartDocument(); tw.WriteStartElement("treeview"); tw.WriteAttributeString("title","Licenses Tool"); tw.WriteStartElement("custom-parameters"); tw.WriteStartElement("param"); tw.WriteAttributeString("name","shift-width"); tw.WriteAttributeString("value","15"); tw.WriteEndElement(); tw.WriteStartElement("param"); tw.WriteAttributeString("name","img-directory"); tw.WriteAttributeString("value","images/"); tw.WriteEndElement(); tw.WriteEndElement(); int level=0; string IdElement=""; Level.add(""); string Name=""; string IdPrduit=""; string IdParent=""; string License=""; string PrevIdParent=""; string PrevIdElement=""; bool FlagElementFirst= true ; foreach(DataRow r in DT.Rows) { if (FlagElementFirst == true) { Level.Remove(0); Level.add(r["idSetParent"].ToString()); } IdElement = r["idSet"].ToString(); Name = r["setName"].ToString(); IdPrduit = r["idProduct"].ToString(); IdParent = r["idSetParent"].ToString(); License = r["license"].ToString(); if(( Level[IdParent]>=level ||level==0 )) { if((IdParent=="" || IdParent!=PrevIdParent ) && (IdPrduit=="") ) { Console.WriteLine("Name"); tw.WriteStartElement("folder"); tw.WriteAttributeString("title",Name); if (FlagElementFirst == true) { tw.WriteAttributeString("url",IdElement); } else { tw.WriteAttributeString("url",IdElement); } level++ ; Level.add(IdElement); PrevIdParent=IdParent; PrevIdElement =IdElement; } else if((IdParent==PrevIdParent)&& IdParent!="" && (IdPrduit=="") ) { tw.WriteStartElement("folder"); tw.WriteAttributeString("title",Name); tw.WriteAttributeString("url",IdElement); Level.add(IdElement); PrevIdParent=IdParent; PrevIdElement =IdElement; level++; } else if(IdPrduit!="")

                J Offline
                J Offline
                John Honan
                wrote on last edited by
                #7

                Okay, now that I've seen all your code, I can tell you exactly where you're going wrong. GenerateTreeXml.aspx does correctly generate XML, as I tried it for myself. However, the method you're using to 'read' in the XML it generates is incorrect: Dim XR As XmlTextReader = New XmlTextReader(Server.MapPath("GenerateTreeXml.aspx")) (Converted to vb.net, but does the same thing). The problem with the above statement is that you are actually telling ASP to go to that file in that directory and read its contents. So, ASP goes off and finds 'GenerateTreeXml.Aspx' on your hard disk, and reads it in. It does exactly what you've told it to. It doesn't run the ASP code in that file, it just reads the ASPX file straight from disk - as if you went into notepad and opened it up. Go into notepad and open it up, and you'll see what your XmlTextReader is seeing... and sure enough, it's "<%@ Page Lan..." So you'll have to find a different way. I can see what you're trying to do - you're trying to get the output of GenerateTreeXml in XML format in such a way as you can use it in other pieces of your project. I have no quick solution for you at the moment. But at least I told you what was wrong with your code! :) John. www.silveronion.com[^]

                1 Reply Last reply
                0
                • Z zoltix

                  Hi, I have a problem with streaming XML. I have created an aspx which return me an xml file format (Type text/xml, Encoding.UTF8). Also now, I try to read this stream in the XmlTextReader but I receive an Error Message when I parse it. And of course, I don't understand that. Could you help me? It is a bit urgent.... Thanks a lot Code Source XmlTextReader XR = new XmlTextReader(Server.MapPath("GenerateXmlTreeView.aspx")); while(!XR.EOF){ XR.ReadElementString(); //Here Thrown exception } Sr.Close(); When I run may aspx Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Xml.XmlException: The '%' character, hexadecimal value 0x25, cannot begin a name. Line 1, position 2. Source Error: Source XML:

                  R Offline
                  R Offline
                  Ryan Cromwell
                  wrote on last edited by
                  #8

                  c:\YourProjectPathHere\GenerateXmlTreeView.aspx is what you are getting from Server.MapPath("GenerateXmlTreeView.aspx") You want: http://

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups