This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String variable

 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

I am using String variable for storing xml as a string but it gives lot of syntax arrors saying expected ; tokens ......

private String data = "<?xml version="1.0" encoding= "utf-8 standalone="no" ?> <!-- Race Card Data --> <!-- Indiana Downs Race: 1 Number of Pools: 12 --> <RaceCardData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="MECRaceCardData.xsd"> <DocumentSerialNumber>109089</DocumentSerialNumber> <TimeStamp>2008-01-04 08:03:31</TimeStamp> <SequenceNumber>1</SequenceNumber> <Event> <EventName>Indiana Downs</EventName> <EventCode>IJN</EventCode> EventDate>2008-01-04</EventDate> </Event> <Race> <RaceNumber>1</RaceNumber> <RaceName>N/W $2000 IN LAST 4 STARTS (W/O $40,000 (IS MARES|</RaceName> <NumberOfBettingInterests>4</NumberOfBettingInterests> <RaceBreed>Unknown</RaceBreed> <Purse>5,800.00</Purse> <Grade /> <Distance>0 Unknown</Distance> <Class>N/A</Class> <TrackSurface>Dirt</TrackSurface> <SexRestrictions>Unknown</SexRestrictions> <AgeRestrictions>U</AgeRestrictions> <ProjectedPostTime>9:42 AM</ProjectedPostTime> </Race> </RaceCardData> ";

thanks

please help
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your XML includes " (double quote) characters. To include these in a Java literal String, they must be "escaped" with a backslash; or you could use single quotes. So either of these would work:

private String data = "<?xml version=\"1.0\" ...

or

private String data = "<?xml version='1.0' ...

You have to go through your String and change every " character, not just the ones I've shown here.
 
Neha Agarwal
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String data = "<?xml version= \"1.0\" encoding= \"utf-8 standalone=\"no\" ?> <!-- Race Card Data -->" +
"<!-- Indiana Downs Race: 1 Number of Pools: 12 --> <RaceCardData xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance" +
"\" xsi:schemaLocation=\"MECRaceCardData.xsd\"> <DocumentSerialNumber>109089</DocumentSerialNumber> <TimeStamp>2008-01-04 08:03:31" +
"</TimeStamp> <SequenceNumber>1</SequenceNumber> <Event> <EventName>Indiana Downs</EventName> " +
"<EventCode>IJN</EventCode> EventDate>2008-01-04</EventDate> </Event> <Race> <RaceNumber>1</RaceNumber>" +
"<RaceName>N/W $2000 IN LAST 4 STARTS (W/O $40,000 (IS MARES|</RaceName> <NumberOfBettingInterests>4</NumberOfBettingInterests>" +
"<RaceBreed>Unknown</RaceBreed> <Purse>5,800.00</Purse> <Grade /> <Distance>0 Unknown</Distance> <Class>N/A</Class> <TrackSurface>Dirt" +
"</TrackSurface> <SexRestrictions>Unknown</SexRestrictions> <AgeRestrictions>U</AgeRestrictions> <ProjectedPostTime>9:42 AM</ProjectedPostTime>" +
"</Race> </RaceCardData> ";
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thank you guys. It worked as you said but temporarily solution the thing is I have web services and my web client. My client will send xml file in a String parameter and my web services will recieve it as String parameter. Now, the problem is my client will not edit or change the String quotes into single character or escape String quotes . How do i progmatically handel this issue ?. The other thing is when I pass xml file as a String to web services on server side when I print String parameter there are no String double quotes. I dont want my client should edit the xml file.

please help!

thanks
gurpreet
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is only a problem when the XML appears in the text of your program like this. Once the XML data is in a String -- whether it be because it was sent over the network, read from a file, etc -- then everything is fine. The escaping stuff is just necessary for the compiler, when it's reading the String contents from a Java source file this way. Make sense?
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I Thank you for your response. I do understand. Let me now talk with the client meanwhile I would love to hear any opinion in this matter. Your help will be greatfull.

thank you

gurpreet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic