Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 6th, 2007, 06:27 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
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.--
Reply With Quote
  #2 (permalink)  
Old February 7th, 2007, 05:14 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
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;
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.