I have a problem with streaming XML.
-
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:
-
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:
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.
-
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.
-
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=-
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[^]
-
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[^]
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=-
-
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=-
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!="")
-
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!="")
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[^]
-
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:
c:\YourProjectPathHere\GenerateXmlTreeView.aspx is what you are getting from Server.MapPath("GenerateXmlTreeView.aspx") You want: http://