| Author |
String variable
|
Gurpreet Saini
Ranch Hand
Joined: Jun 09, 2002
Posts: 295
|
|
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
Joined: Jul 08, 2003
Posts: 24061
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Neha Agarwal
Greenhorn
Joined: Mar 12, 2008
Posts: 16
|
|
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
Joined: Dec 11, 2004
Posts: 13410
|
|
"Neha Java", Please check your private messages. -Ben
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Gurpreet Saini
Ranch Hand
Joined: Jun 09, 2002
Posts: 295
|
|
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
Joined: Jul 08, 2003
Posts: 24061
|
|
|
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
Joined: Jun 09, 2002
Posts: 295
|
|
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
|
 |
 |
|
|
subject: String variable
|
|
|