Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 March 26th, 2011, 03:25 AM
Registered User
 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing an Xml with No Xml Declaration

Hello Guys,

I am retrieving a XML file from a Url but the file returned contains xml tags but no Xml declaration and when i tried parsing it with SAX Parser i am getting the following errors

03-26 10:17:03.018: WARN/System.err(274): org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column 0: no element found

03-26 01:07:31.181: WARN/System.err(274): at org.apache.harmony.xml.ExpatParser.finish(ExpatPar ser.java:553)

03-26 01:07:31.181: WARN/System.err(274): at org.apache.harmony.xml.ExpatParser.parseDocument(E xpatParser.java:483)

03-26 01:07:31.181: WARN/System.err(274): at org.apache.harmony.xml.ExpatReader.parse(ExpatRead er.java:320)

03-26 01:07:31.181: WARN/System.err(274): at org.apache.harmony.xml.ExpatReader.parse(ExpatRead er.java:277)

03-26 01:07:31.181: WARN/System.err(274): at org.MystiqueCell.SevenDayForecast$1.onClick(SevenD ayForecast.java:50)



Is there a work around in parsing such files, Any help in this regard is appreciated

Thanks & Regards,
Zoheb
 
Old March 26th, 2011, 04:08 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

A lack of an XML declaration shouldn't be a problem. But I can't really say more without actually seeing the XML file you are talking about.

If the URL you refer to is a public URL then tell us what it is, otherwise try showing us the XML itself, and we may be able to help.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 26th, 2011, 05:31 AM
Registered User
 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi sam,

The url is not public the Xml however is this

<aws:weather xmlns:aws="http://www.aws.com/aws">
<aws:api version="2.0"/>
<aws:WebURL>http://weather.weatherbug.com/India/Bangalore-weather/local-forecast/7-day-forecast.html?ZCode=Z5546&amp;Units=1</aws:WebURL>
<aws:forecasts type="Detailed" date="Fri, 25 Mar 2011 18:00:00 GMT">
<aws:location>
<aws:city>Bangalore</aws:city>
<aws:citycode>64130</aws:citycode>
<aws:country>India</aws:country>
</aws:location>
<aws:forecast>
<aws:title alttitle="SAT">Saturday</aws:title>
<aws:short-prediction>Partly Cloudy</aws:short-prediction>
<aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image>
<aws:description>Saturday</aws:description>
<aws:prediction> Partly cloudy. Temperature of 34&amp;deg;C. Winds E 5km/h. Humidity will be 51% with a dewpoint of 22&amp;deg; and feels-like temperature of 38&amp;deg;C. </aws:prediction>
<aws:high units="°C">34</aws:high>
<aws:low units="°C">21</aws:low>
</aws:forecast>
<aws:forecast>
<aws:title alttitle="SUN">Sunday</aws:title>
<aws:short-prediction>Partly Cloudy</aws:short-prediction>
<aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image>
<aws:description>Sunday</aws:description>
<aws:prediction> Partly cloudy. Temperature of 34&amp;deg;C. Winds NE 21km/h. Humidity will be 54% with a dewpoint of 24&amp;deg; and feels-like temperature of 41&amp;deg;C. </aws:prediction>
<aws:high units="°C">34</aws:high>
<aws:low units="°C">20</aws:low>
</aws:forecast>
<aws:forecast>
<aws:title alttitle="MON">Monday</aws:title>
<aws:short-prediction>Mostly Cloudy</aws:short-prediction>
<aws:image isNight="0" icon="cond024.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond024.gif</aws:image>
<aws:description>Monday</aws:description>
<aws:prediction> Mostly cloudy. Temperature of 32&amp;deg;C. Winds NE 22km/h. Humidity will be 60% with a dewpoint of 23&amp;deg; and feels-like temperature of 38&amp;deg;C. </aws:prediction>
<aws:high units="°C">32</aws:high>
<aws:low units="°C">19</aws:low>
</aws:forecast>
<aws:forecast>
<aws:title alttitle="TUE">Tuesday</aws:title>
<aws:short-prediction>Mostly Cloudy</aws:short-prediction>
<aws:image isNight="0" icon="cond024.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond024.gif</aws:image>
<aws:description>Tuesday</aws:description>
<aws:prediction> Mostly cloudy. Temperature of 33&amp;deg;C. Winds NE 26km/h. Humidity will be 58% with a dewpoint of 23&amp;deg; and feels-like temperature of 39&amp;deg;C. </aws:prediction>
<aws:high units="°C">33</aws:high>
<aws:low units="°C">18</aws:low>
</aws:forecast>
<aws:forecast>
<aws:title alttitle="WED">Wednesday</aws:title>
<aws:short-prediction>Mostly Cloudy</aws:short-prediction>
<aws:image isNight="0" icon="cond024.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond024.gif</aws:image>
<aws:description>Wednesday</aws:description>
<aws:prediction> Mostly cloudy. Temperature of 33&amp;deg;C. Winds NE 28km/h. Humidity will be 58% with a dewpoint of 23&amp;deg; and feels-like temperature of 38&amp;deg;C. </aws:prediction>
<aws:high units="°C">33</aws:high>
<aws:low units="°C">18</aws:low>
</aws:forecast>
<aws:forecast>
<aws:title alttitle="THU">Thursday</aws:title>
<aws:short-prediction>Partly Cloudy</aws:short-prediction>
<aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image>
<aws:description>Thursday</aws:description>
<aws:prediction> Partly cloudy. Temperature of 33&amp;deg;C. Winds ENE 30km/h. Humidity will be 56% with a dewpoint of 23&amp;deg; and feels-like temperature of 39&amp;deg;C. </aws:prediction>
<aws:high units="°C">33</aws:high>
<aws:low units="°C">18</aws:low>
</aws:forecast>
<aws:forecast>
<aws:title alttitle="FRI">Friday</aws:title>
<aws:short-prediction>Partly Cloudy</aws:short-prediction>
<aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image>
<aws:description>Friday</aws:description>
<aws:prediction> Partly cloudy. Temperature of 29&amp;deg;C. Winds NE 20km/h. Humidity will be 48% with a dewpoint of 17&amp;deg; and feels-like temperature of 29&amp;deg;C. </aws:prediction>
<aws:high units="°C">29</aws:high>
<aws:low units="°C">18</aws:low>
</aws:forecast>
</aws:forecasts>
</aws:weather>


I extended DefaultHandler to parse the data present within the tags but met with those errors i posted earlier, I however had no issues parsing an xml file with XML declaration.if you can successfully parse this file and show me an example of doing so it would be Big Help, thanks for taking interest in the problem tough





Similar Threads
Thread Thread Starter Forum Replies Last Post
No XML Document Declaration Line heightsofdelites XSLT 2 October 14th, 2010 03:17 AM
XML::Simple parsing xml geek.shrek Perl 1 August 19th, 2009 10:32 PM
xml declaration not displayed zsheema XSLT 10 May 15th, 2008 04:36 AM
xml declaration chroniclemaster1 XML 0 September 20th, 2007 02:00 PM
omit-xml-declaration dextermagnific XSLT 3 August 4th, 2006 09:55 AM





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