Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What Happened to the XmlTextWriter ? It started to bomb Recently.....

Status
Not open for further replies.

wbochar

IS-IT--Management
Mar 14, 2003
72
US
There is something rotten going on here. I had a segment of code that was working perfectly and recently it started acting funny -- and no matter what I do it doesnt want to act at all like it should nor can I figure out what is going on.

The problem...

The code is for an article to XML (for loading into flash) conversion. The code below is a stripped down version. I had a sql server loop ripping through some articles based on date and whatever. As of today I opened the file through the browser to review the contents and bammo an error. It was telling me that the XML data on line 3 at position 800 was not in the correct position. After alot of juglling information around, I got the raw output and checked it -- it had generated the XML (from start to finsih) three times. At first I went and checked to see if any changes had been made and the source control said No. Then checked the SQL, maybe something changed there -- no matter what I did I kept on getting three times or twice. So I removed the sql code and still is doubling it up...

ARG! I am sitting here at work (after hours) looking at this thinking I'd rather be at home eating pizza and reading a good book.

Its very wierd; it worked fine and now it doesnt.I havent changed it. This code below doesnt bomb the browser, but it doesnt generate the style sheet version it used to do.

Has there been any server updates recently that might have affected this?

Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Text;
using System.Configuration;


private void Page_Load(object sender, System.EventArgs e)
{
     //Response.OutputStream for output to browser
     XmlTextWriter XMLWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
			
//Create Prolog and encoding tags along with opening the article_list tag 
  XMLWriter.WriteStartDocument();
  XMLWriter.WriteComment("XML Article List");
  XMLWriter.WriteStartElement("article_list");

  string ArticleUrlLocation;
  ArticleUrlLocation= "URL INFO";
  XMLWriter.WriteStartElement("article");
  XMLWriter.WriteAttributeString("id", "6666");
  XMLWriter.WriteAttributeString("title_colour", "6666");
  XMLWriter.WriteAttributeString("language", "6666");
  XMLWriter.WriteAttributeString("image", "Car.jpg");
  XMLWriter.WriteAttributeString("url", ArticleUrlLocation);
  XMLWriter.WriteAttributeString("animation", "6666");
  XMLWriter.WriteAttributeString("transistion","6666");
  XMLWriter.WriteAttributeString("total_time","6666");
  XMLWriter.WriteElementString("titletext"," START 12345678901234567890");
  XMLWriter.WriteElementString("descriptiontext","1234567890123456789012345678901234567890 END");
  XMLWriter.WriteEndElement();

  XMLWriter.WriteEndElement();
  XMLWriter.WriteEndDocument();
  XMLWriter.Close(); 
}

 
Did you .Flush() the output of your XmlTextWriter? It's supposed to happen automatically when you close it, but it might be worthwhile to add a call to it right before you .Close() it.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I tried the FLush but it didnt fly. I got the same results..

wbochar

 
Are you checking for a postback?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
The Postback isnt affecting it. I can't seem to get this to go. This is a textbook example and it dumps the xml document twice!.. I cant seem to figure it out..
 
I basically used the add new item, picked a web form, then cleared out the html and just left
Code:
<%@ Page language="c#" Codebehind="XMLTEST1.aspx.cs" AutoEventWireup="false" Inherits="XXXX.XMLTEST1" %>
in the top of the page. Then I opened the cs file and did the additions marked with comments below...

Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

// Added this
using System.Xml;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Text;
using System.Configuration;
// to this

namespace corp
{
	/// <summary>
	/// Summary description for XMLTEST1.
	/// </summary>
	public class XMLTEST1 : System.Web.UI.Page
	{
		private void Page_Load(object sender, System.EventArgs e)
		{

// added the following into the pageload

			if (!IsPostBack)
			{
		
				//xmldata.Text for debug or Response.OutputStream for output to browser
				XmlTextWriter XMLWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
			
				//Create Prolog and encoding tags along with opening the article_list tag 
				XMLWriter.WriteStartDocument();
				//XMLWriter.WriteComment("Mevotech.com Article List for Flash Banner Content");
				//XMLWriter.WriteComment(("Content Copyright Mevotech ("+DateTime.Now+")"));
				//XMLWriter.WriteComment("Code Written by Wolfgang Bochar (2004-2005)");
				//	XMLWriter.WriteComment("Last Changes to Code:");
				//	XMLWriter.WriteComment("=====================");
				//	XMLWriter.WriteComment("Renamed Time Tag to total_time (for flash compatibility)");
				//	XMLWriter.WriteComment("=====================");
				//	XMLWriter.WriteComment("Revision 1.02");
				XMLWriter.WriteStartElement("article_list");
				string ArticleUrlLocation;

				ArticleUrlLocation= "URL INFO";


				XMLWriter.WriteStartElement("article");
				XMLWriter.WriteAttributeString("id", "6666");
				XMLWriter.WriteAttributeString("title_colour", "6666");
				XMLWriter.WriteAttributeString("language", "6666");
				XMLWriter.WriteAttributeString("image", "Car.jpg");
				XMLWriter.WriteAttributeString("url", ArticleUrlLocation);
				XMLWriter.WriteAttributeString("animation", "6666");
				XMLWriter.WriteAttributeString("transistion","6666");
				XMLWriter.WriteAttributeString("total_time","6666");


				XMLWriter.WriteElementString("titletext"," START lfkash flkajshflk asjdfh lkashflksfh lksafhlk asjgdfhl ksajfhl kas");
				XMLWriter.WriteElementString("descriptiontext","asdf asdfsafaskjdfalksfhsalkjfh lsakjhf laksjfhl sakhfl sakfhlkasjfhl asjkhf lasfh alskhfl askjfl askjfhlksa jfhlkasjhfl askjfhl sakjfhlsa kjfhlaskfh lsakjf lsakjfh lsakfh lsakf lsakfhlsakh flaksjf laksjfhlksajfhlaskfhlaskjgf lassadgjfhalksj fhlkasjhfl akshflkas END12345");
				XMLWriter.WriteEndElement();




				// Post loop xml cleanup

				XMLWriter.WriteEndElement();
				XMLWriter.WriteEndDocument();
				XMLWriter.Flush();
				XMLWriter.Close(); 

			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top