Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2007, 06:27 AM
Authorized User
 
Join Date: Mar 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default Unexpected end of file while parsing...

Hi Group,

I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception: “Unexpected end of file while parsing Name has occurred” is being thrown.

Following is the part o xml I am trying to read:
 <CHECK_ITEM_OUT>
 <ITEM id="">

  <ITM_NUMBER>1</ITM_NUMBER>
  <MATERIAL>001</MATERIAL>
   <DEALER_CODE>DEL_One</DEALER_CODE>
  <BRAND>Bridgestone</BRAND>
  <HIERARCHY>HAR001</HIERARCHY>
  <NET_PRICE>123.12</NET_PRICE>
  <CURRENCY>EURO</CURRENCY>
</ITEM>
 <ITEM id="">

  <ITM_NUMBER>2</ITM_NUMBER>
  <MATERIAL>002</MATERIAL>
   <DEALER_CODE>DEL_Two</DEALER_CODE>
  <BRAND>Firestone</BRAND>
  <HIERARCHY>HAR002</HIERARCHY>
  <NET_PRICE>453.12</NET_PRICE>
  <CURRENCY>EURO</CURRENCY>
</ITEM>
<ITEM id="">

  <ITM_NUMBER>3</ITM_NUMBER>
  <MATERIAL>003</MATERIAL>
   <DEALER_CODE />
  <BRAND>FIRESTONE</BRAND>
  <HIERARCHY>HAR001</HIERARCHY>
  <NET_PRICE>24.12</NET_PRICE>
  <CURRENCY>EURO</CURRENCY>
</ITEM>
</CHECK_ITEM_OUT>

When I am trying to read the <BRAND>FIRESTONE</BRAND> (In Third item in the list), I am getting the “Unexpected end of file while parsing Name has occurred” exception. I am able to read the values from <BRAND> element for first two elements.
Following is the code I am using for reading the xml.

case "BRAND":
  if (!xmlTextReader.IsEmptyElement)
   productInfo.Brand = xmlTextReader.ReadElementContentAsString(); break;

I also have searched net for this problem but I found nothing useful#61516;

Please let me know if I am doing something wrong or missing on something.

Thanks,
Anup Daware


Best Regards,
Anup
&lt;Today is the first day of your rest of life.. Make most of it&gt;
__________________
--Everything you can imagine is real.--
 
Old February 7th, 2007, 05:14 AM
Authorized User
 
Join Date: Mar 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default

Hi Group,

The problem is solved :)

Following lines were creating the problem:

  StreamWriter streamWriter = new StreamWriter(responseStream);

  streamWriter.Write(responseXml); //responseXml is a string

The the default buffer of StreamWriter is 4kb and the string responseXml is more than that, thus only a portion of my xml was being used by XmlTextWriter which is using responseStream: And that was the reason of Unexpected end of file while parsing Name has occurred exception.



Solution:


Rather than using the the StreamWriter, I directly used the responseStream.Write; for this I converted the string to byte array. Following is the code for it.

            String responseXml = GetResponseStream(uri, searchRequestXML);
            System.Text.UTF8Encoding ob = new UTF8Encoding();
            byte[] arr2 = ob.GetBytes(responseXml);
            responseStream.Write(arr2,0,arr2.Length);
            responseStream.Seek(0, SeekOrigin.Begin);
            XmlTextReader xmlTextReader = new XmlTextReader(responseStream)




Well the conclusion is StreamWriter has a default size of 4KB which is not increased dynamically, and this is really unexpected.

Best Regards,
Anup Daware

Best Regards,
Anup
&lt;Today is the first day of your rest of life.. Make most of it&gt;





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unexpected end of file while parsing PI... rageypeep .NET Framework 3.5 2 June 20th, 2008 04:18 AM
Help Parsing XML File Sojan80 XML 7 January 7th, 2008 06:09 PM
Parse error: parse error, unexpected $end Ayodeji Adegbaju Pro PHP 3 January 12th, 2007 12:21 PM
unexpected end of file Spivonious Visual C++ 2 September 21st, 2004 07:44 AM
unexpected end of file question Spivonious C++ Programming 4 September 15th, 2004 02:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.