• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Parsing Problem

 
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys I have a problem parsing this particular node, It goes like


<prediction>
Scattered showers. There is a 50% chance of precipitation. Cloudy. Temperature of 31°C. Winds NNW 12km/h. Humidity will be 66% with a dewpoint of 23° and feels-like temperature of 35°C.
</prediction>


Now the string presented here is required, i know that the callback is received by method characters() where i am doing this


But the string that gets stored is deg:C. only that, How can i retrieve the whole string
After parsing
Expected:Scattered showers. There is a 50% chance of precipitation. Cloudy. Temperature of 31°C. Winds NNW 12km/h. Humidity will be 66% with a dewpoint of 23° and feels-like temperature of 35°C.

Actual:deg:C.

Am i doing something wrong here

 
Sheriff
Posts: 26961
84
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course you're doing something wrong. You have incorrect output, don't you? So yes, you're doing something wrong.

But more specifically, you wanted to know what, right? Fortunately your question is the one and only question in this forum's FAQ: XmlFaq (just follow the link).
 
zoheb hassan
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it paul Thanks, Now the string that i am retrieving contains entity reference element for displaying °C but the string returned reads the entity reference value as is with "ampersand deg;"How do i make sure that the string which i will be putting up for display contains Symbol °C and not ampersand deg;
 
Paul Clapham
Sheriff
Posts: 26961
84
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't matter what the string actually contains, all that matters is how it appears when you display it. Which of course puts the requirement onto whatever you choose to display the string.

If you choose HTML to display it (and take care not to escape that entity) then &deg; will appear to the viewer as °. If you choose something else, then it's up to you to interpret the entities.

But I'm a bit confused. Such an entity isn't legal in an XML document unless a DTD which declares the entity is attached to the document. And if that's the case then the parser should replace the entity (&deg;) by its declared value (°). At least that's what I thought. Is any of that relevant to your document?

By the way please don't type rough approximations of this sort of thing (like "ampersand deg;" for example) as it makes it hard to discuss what is actually happening. To type the entity name &deg; into a post and have the forum display it correctly, type in the escaped version of the entity like this: &amp;deg; and the forum software will automatically unescape it to appear as &deg;. There's also a Preview button which you can use before you post, to see what your post is going to look like.
 
zoheb hassan
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey paul thanks for the reply, actually working on an android application the url retrieves the data in xml format which i parse and put it into an Data Object and then display it for the user of course i can use a String.replaceAll("&deg;","degrees) method to display it as "degrees" .But what concerns me is the amount of space taken by this String for display on mobile device and there are more than seven of them. But still working on an way to beat that if there is an possibility do let me know
 
Paul Clapham
Sheriff
Posts: 26961
84
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if I found I had to change the string "&deg;" to something human-readable, I would choose the "°" character. So your question about the amount of space to display the word "degrees" doesn't arise, and it's more human-readable anyway.
 
zoheb hassan
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah but how do i force the character ° into a plain String text??
 
Paul Clapham
Sheriff
Posts: 26961
84
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First you find its Unicode code point, by looking it up in the Unicode code charts. You might also find the Character Name index useful.

Then when you find the symbol (its name is "DEGREE SIGN") you will have its code point. Let's suppose the Unicode documentation tells you that it is "abcd". Then you put a Unicode escape into your Java code:
.
 
zoheb hassan
Ranch Hand
Posts: 154
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Paul i used this



and it works like a charm. Thanks a ton Man
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic