By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,837 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,837 IT Pros & Developers. It's quick & easy.

Strange!! Unexpected end of file while parsing Name has occurred

P: n/a
Hi Group,

I am facing a strange problem here:
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” isbeing
thrown.

Following is the part o xml I am trying to read:
<CHECK_ITEM_OUT>
<ITEM id="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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
<BRANDelement 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

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

Thanks,
Anup Daware

Feb 6 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Something to consider, is look at the Dealer_code element. Maybe try
changing it from <DEALER_CODE />
to <DEALER_CODE></DEALER_CODE>, maybe even putting some test value in
there. That's the only thing I can see different in the XML document that
may cause something strange and it does occur just before the brand element.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Anup Daware" <an*********@gmail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
Hi Group,

I am facing a strange problem here:
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="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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
<BRANDelement 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?

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

Thanks,
Anup Daware
Feb 6 '07 #2

P: n/a
Hi Mark,

Thanks for the reply and good observation too :)

I haven't included whole xml here. And I have elements like
<NET_PRICE/prior to <DEALER_CODE/in actual xml, this works fine.

By the way I also tried it with <DEALER_CODE></DEALER_CODEand with
some dummy value in it, but problem didn't solve.
Thanks,
Anup

On Feb 6, 8:09 pm, "Mark Fitzpatrick" <markf...@fitzme.comwrote:
Something to consider, is look at the Dealer_code element. Maybe try
changing it from <DEALER_CODE />
to <DEALER_CODE></DEALER_CODE>, maybe even putting some test value in
there. That's the only thing I can see different in the XML document that
may cause something strange and it does occur just before the brand element.

--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Anup Daware" <anup.daw...@gmail.comwrote in message

news:11**********************@a34g2000cwb.googlegr oups.com...
Hi Group,

I am facing a strange problem here:
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="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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
<BRANDelement 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?

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

Thanks,
Anup Daware

Feb 7 '07 #3

P: n/a
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
On Feb 7, 8:42 am, "Anup Daware" <anup.daw...@gmail.comwrote:
Hi Mark,

Thanks for the reply and good observation too :)

I haven't included whole xml here. And I have elements like
<NET_PRICE/prior to <DEALER_CODE/in actual xml, this works fine.

By the way I also tried it with <DEALER_CODE></DEALER_CODEand with
some dummy value in it, but problem didn't solve.

Thanks,
Anup

On Feb 6, 8:09 pm, "Mark Fitzpatrick" <markf...@fitzme.comwrote:
Something to consider, is look at the Dealer_code element. Maybe try
changing it from <DEALER_CODE />
to <DEALER_CODE></DEALER_CODE>, maybe even putting some test value in
there. That's the only thing I can see different in the XML document that
may cause something strange and it does occur just before the brand element.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Anup Daware" <anup.daw...@gmail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
Hi Group,
I am facing a strange problem here:
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="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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="">
<!-- id = [material] -->
<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
<BRANDelement 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?
Please let me know if I am doing something wrong or missing on
something.
Thanks,
Anup Daware

Feb 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.