Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within XML
Search Coderanch
Advance search
Google search
Register / Login
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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
XML and Related Technologies
weird characters translation json into XML
Tony Evans
Ranch Hand
Posts: 681
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I translate XML
<?xml version="1.0" encoding="UTF-8" ?> <Response ResponseReference="REF_T_023_2494-697-096302233852542" ResponseSequence="2"> <ResponseDetails Language="en"> <BookingResponse> <BookingReferences> <BookingReference ReferenceSource="client"><![CDATA[VLD_PAX_ROOM_KA_04]]></BookingReference> <BookingReference ReferenceSource="api"><![CDATA[68748]]></BookingReference> </BookingReferences> <BookingCreationDate>2014-03-17</BookingCreationDate> <BookingDepartureDate>2014-04-15</BookingDepartureDate> <BookingName><![CDATA[MR RORY GULLIVER]]></BookingName> <BookingPrice Currency="GBP" Gross="472.00" Commission="47.20" Nett="424.80"></BookingPrice> <BookingStatus Code="CP"><![CDATA[Pending Confirmation]]></BookingStatus> <PaxNames> <PaxName PaxId="1"><![CDATA[Mr Rory Gulliver]]></PaxName> <PaxName PaxId="2"><![CDATA[Ms Fiona Gulliver]]></PaxName> <PaxName PaxId="3"><![CDATA[Mr Sean Gulliver]]></PaxName> <PaxName PaxId="4"><![CDATA[Mr Dean Gulliver]]></PaxName> <PaxName PaxId="5"><![CDATA[Mr Paddy Gulliver]]></PaxName> <PaxName PaxId="6"><![CDATA[Mrs Sharon Gulliver]]></PaxName> <PaxName PaxId="7"><![CDATA[Mr Murphy Gulliver]]></PaxName> <PaxName PaxId="8"><![CDATA[Mrs Meghan Gulliver]]></PaxName> </PaxNames> <BookingItems> <BookingItem ItemType="hotel"> <ItemReference>2</ItemReference> <ItemCity Code="LON"><![CDATA[London]]></ItemCity> <Item Code="96Y"><![CDATA[Stefania Pani]]></Item> <ItemPrice Currency="GBP" Gross="118.00" Commission="11.80" Nett="106.20"></ItemPrice> <ItemStatus Code="C "><![CDATA[Confirmed or Completed]]></ItemStatus> <ItemConfirmationReference>TTAF020340</ItemConfirmationReference> <HotelItem> <PeriodOfStay> <CheckInDate>2014-04-15</CheckInDate> <CheckOutDate>2014-04-17</CheckOutDate> </PeriodOfStay> <HotelPaxRoom Adults="2" Children="0" Cots="0" Id="001:96Y:16132:S12674:16047:23992"> <Description><![CDATA[Standard Twin]]></Description> <PaxIds> <PaxId>3</PaxId> <PaxId>4</PaxId> </PaxIds> </HotelPaxRoom> <Meals> <Basis Code="N"><![CDATA[None]]></Basis> </Meals> </HotelItem> <ChargeConditions> <ChargeCondition Type="cancellation"> <Condition Charge="true" FromDay="0" ToDay="0" Currency="GBP" ChargeAmount="118.00"></Condition> <Condition Charge="true" FromDay="1" ToDay="1" Currency="GBP" ChargeAmount="59.00"></Condition> <Condition Charge="false" FromDay="2"></Condition> </ChargeCondition> <ChargeCondition Type="amendment" Allowable="false"></ChargeCondition> <PassengerNameChange Allowable="false" FromDay="0"></PassengerNameChange> </ChargeConditions> </BookingItem> <BookingItem ItemType="hotel"> <ItemReference>2</ItemReference> <ItemCity Code="LON"><![CDATA[London]]></ItemCity> <Item Code="96Y"><![CDATA[Stefania Pani]]></Item> <ItemPrice Currency="GBP" Gross="118.00" Commission="11.80" Nett="106.20"></ItemPrice> <ItemStatus Code="C "><![CDATA[Confirmed or Completed]]></ItemStatus> <ItemConfirmationReference>TTAF020340</ItemConfirmationReference> <HotelItem> <PeriodOfStay> <CheckInDate>2014-04-15</CheckInDate> <CheckOutDate>2014-04-17</CheckOutDate> </PeriodOfStay> <HotelPaxRoom Adults="2" Children="0" Cots="0" Id="001:96Y:16132:S12674:16047:23992"> <Description><![CDATA[Standard Twin]]></Description> <PaxIds> <PaxId>3</PaxId> <PaxId>4</PaxId> </PaxIds> </HotelPaxRoom> <Meals> <Basis Code="N"><![CDATA[None]]></Basis> </Meals> </HotelItem> <ChargeConditions> <ChargeCondition Type="cancellation"> <Condition Charge="true" FromDay="0" ToDay="0" Currency="GBP" ChargeAmount="118.00"></Condition> <Condition Charge="true" FromDay="1" ToDay="1" Currency="GBP" ChargeAmount="59.00"></Condition> <Condition Charge="false" FromDay="2"></Condition> </ChargeCondition> <ChargeCondition Type="amendment" Allowable="false"></ChargeCondition> <PassengerNameChange Allowable="false" FromDay="0"></PassengerNameChange> </ChargeConditions> </BookingItem> </BookingItems> </BookingResponse> </ResponseDetails> </Response>
Into json
{"@ResponseReference":"REF_T_008_2619-51-017386724793357","@ResponseSequence":"1","ResponseDetails":{"@Language":"en","BookingResponse":{"BookingReferences":[{"@ReferenceSource":"client","#text":"QUICK003"},{"@ReferenceSource":"api","#text":"72847"}],"BookingCreationDate":"2014-05-19","BookingDepartureDate":"2014-06-06","BookingName":"GRAHAM QUICK","BookingPrice":{"@Commission":"6000","@Currency":"JPY","@Gross":"60000","@Nett":"54000"},"BookingStatus":{"@Code":"C ","#text":"Confirmed or Completed"},"PaxNames":[{"@PaxId":"1","#text":"Graham Quick"},{"@PaxId":"2","#text":"A A"}],"BookingItems":[{"@ItemType":"hotel","ItemReference":"1","ItemCity":{"@Code":"LON","#text":"London"},"Item":{"@Code":"97R","#text":"Swamy Hotel"},"ItemPrice":{"@Commission":"6000","@Currency":"JPY","@Gross":"60000","@Nett":"54000"},"ItemStatus":{"@Code":"C ","#text":"Confirmed or Completed"},"ItemConfirmationReference":"TTAF022865","HotelItem":{"PeriodOfStay":{"CheckInDate":"2014-06-06","CheckOutDate":"2014-06-08"},"HotelRooms":[{"@Code":"DB","@Id":"001:97R:18618:S15800:22415:30676","Description":"Business Double/Double","PaxIds":["1","2"]}],"Meals":[{"@Code":"N","#text":"None"}]},"ChargeConditions":{"ChargeCondition":[{"Condition":[{"@Charge":"true","@ChargeAmount":"60000","@Currency":"JPY","@FromDay":"0","@ToDay":"0"},{"@Charge":"true","@ChargeAmount":"30000","@Currency":"JPY","@FromDay":"1","@ToDay":"1"},{"@Charge":"true","@ChargeAmount":"6000","@Currency":"JPY","@FromDay":"2","@ToDay":"3"},{"@Charge":"false","@FromDay":"4"}]},{"@MaximumPossibleChargesShown":"true","Condition":[{"@Charge":"true","@ChargeAmount":"60000","@Currency":"JPY","@FromDay":"0","@ToDay":"0"},{"@Charge":"true","@ChargeAmount":"4000","@Currency":"JPY","@FromDay":"1","@ToDay":"3"},{"@Charge":"false","@FromDay":"4"}]}],"PassengerNameChange":{"@Allowable":"true"}}}]}}}
using the code
public void convertToJson(String data){ XMLSerializer xmlSerializer = new XMLSerializer(); JSON json = xmlSerializer.read( data ); System.out.println(json.toString()); }
Then back into XML again
public String convertToXML(String jsonData){ XMLSerializer serializer = new XMLSerializer(); JSON json = JSONSerializer.toJSON( jsonData ); String xml = serializer.write( json ); return xml; }
I get the output
<?xml version="1.0" encoding="UTF-8"?> <o ResponseReference="REF_T_008_2619-51-017386724793357" ResponseSequence="1"> <ResponseDetails class="object" Language="en"> <BookingResponse class="object"> <BookingCreationDate type="string">2014-05-19 </BookingCreationDate> <BookingDepartureDate type="string">2014-06-06 </BookingDepartureDate> <BookingItems class="array"> <e class="object" ItemType="hotel"> <ChargeConditions class="object"> <ChargeCondition class="array"> <e class="object"> <Condition class="array"> <e class="object" Charge="true" ChargeAmount="60000" Currency="JPY" FromDay="0" ToDay="0" /> <e class="object" Charge="true" ChargeAmount="30000" Currency="JPY" FromDay="1" ToDay="1" /> <e class="object" Charge="true" ChargeAmount="6000" Currency="JPY" FromDay="2" ToDay="3" /> <e class="object" Charge="false" FromDay="4" /> </Condition> </e> <e class="object" MaximumPossibleChargesShown="true"> <Condition class="array"> <e class="object" Charge="true" ChargeAmount="60000" Currency="JPY" FromDay="0" ToDay="0" /> <e class="object" Charge="true" ChargeAmount="4000" Currency="JPY" FromDay="1" ToDay="3" /> <e class="object" Charge="false" FromDay="4" /> </Condition> </e> </ChargeCondition> <PassengerNameChange class="object" Allowable="true" /> </ChargeConditions> <HotelItem class="object"> <HotelRooms class="array"> <e class="object" Code="DB" Id="001:97R:18618:S15800:22415:30676"> <Description type="string">Business Double/Double </Description> <PaxIds class="array"> <e type="string">1</e> <e type="string">2</e> </PaxIds> </e> </HotelRooms> <Meals class="array"> <e class="object" Code="N">None</e> </Meals> <PeriodOfStay class="object"> <CheckInDate type="string">2014-06-06</CheckInDate> <CheckOutDate type="string">2014-06-08</CheckOutDate> </PeriodOfStay> </HotelItem> <Item class="object" Code="97R">Swamy Hotel</Item> <ItemCity class="object" Code="LON">London</ItemCity> <ItemConfirmationReference type="string">TTAF022865 </ItemConfirmationReference> <ItemPrice class="object" Commission="6000" Currency="JPY" Gross="60000" Nett="54000" /> <ItemReference type="string">1</ItemReference> <ItemStatus class="object" Code="C ">Confirmed or Completed </ItemStatus> </e> </BookingItems> <BookingName type="string">GRAHAM QUICK</BookingName> <BookingPrice class="object" Commission="6000" Currency="JPY" Gross="60000" Nett="54000" /> <BookingReferences class="array"> <e class="object" ReferenceSource="client">QUICK003</e> <e class="object" ReferenceSource="api">72847</e> </BookingReferences> <BookingStatus class="object" Code="C ">Confirmed or Completed</BookingStatus> <PaxNames class="array"> <e class="object" PaxId="1">Graham Quick</e> <e class="object" PaxId="2">A A</e> </PaxNames> </BookingResponse> </ResponseDetails> </o>
Response has been replaced with o
Thanks for any help
Tony Evans
Ranch Hand
Posts: 681
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
need to add the following code
serializer.setRootName("Response");
set root to the root of the XML you are generating
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Help with this code
attributes
one to many hibernate
Help with this code
Retrieve values from a bean in JSP
More...