-
-
Save atkawa7/a06957d6daf69f622c45f4a18c79362d to your computer and use it in GitHub Desktop.
Revisions
-
Lormenyo renamed this gist
Aug 26, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Lormenyo revised this gist
Aug 26, 2019 . 3 changed files with 106 additions and 133 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,65 +18,61 @@ public static void main(String[] args) throws IOException { } //-------------------------- UNMARSHALLING XML ------------------------------- public static void unmarshalXML(File xmlFile) { try { System.out.println("Unmarshalling XML to Java Object-------"); //creating the JAXB context JAXBContext jContext = JAXBContext.newInstance(USSDMenuRequest.class); //create the unmarshal object Unmarshaller unmarshallerObj = jContext.createUnmarshaller(); //call the unmarshal method USSDMenuRequest request= (USSDMenuRequest) unmarshallerObj.unmarshal(xmlFile); request.setStarCode("124"); request.setKeyWord("Start"); System.out.println(request.getShortCode() + " " + request.getPrompt() ); } catch(Exception e){ e.printStackTrace(); } } -------------------------- MARSHALLING XML ---------------------------------- public static void marshalXML() { try { System.out.println("Marshalling Java Object to XML-------"); //creating the JAXB context JAXBContext jContext = JAXBContext.newInstance(USSDMenuRequest.class); //create the marshaller object Marshaller marshallerObj = jContext.createMarshaller(); //the XML should be properly indented and formatted marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); USSDDynMenuRequest Sendrequest= new USSDMenuRequest(); Sendrequest.setShortCode("124"); Sendrequest.setPrompt("Start"); Sendrequest.setMessageid("0244708099"); Sendrequest.setSessionId("789888886adh"); //calling the marshall method marshallerObj.marshal(Sendrequest, new FileOutputStream("response.xml")); } catch(Exception e){ e.printStackTrace(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,84 +3,64 @@ //import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name="USSDMenuRequest") public class USSDMenuRequest{ private String sessionId; private String messageid; private String shortCode; private String prompt; private String timeStamp; @XmlElement(name="sessionId") public void setSessionId(String sessionId){ this.sessionId = sessionId; } public String getSessionId(){ return sessionId; } public String getMessageid(){ return messageid; } @XmlElement(name="messageid") public void setMessageid(String messageid){ this.messageid = messageid; } @XmlElement(name="shortCode") public void setShortCode(String shortCode){ this.shortCode = shortCode; } public String getShortCode(){ return shortCode; } @XmlElement(name="prompt") public void setPrompt(String prompt){ this.prompt = prompt; } public String getKeyWord(){ return keyWord; } public String getTimeStamp(){ return timeStamp; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> <USSDDynMenuRequest> <sessionId name='sessionId'>$sessionId</sessionId> <messaged name='messageid'>$messageid</messageid> <shortCode name='shortCode'>$shortCode</shortCode> <prompt name='prompt'>$prompt</prompt>" <menu> <value>param1</value> <value>param2</value> <value>param3</value> </menu> <userData name="name">$name</userData> <timeStamp>$timestamp</timeStamp> </USSDMenuRequest> -
Lormenyo revised this gist
Aug 14, 2019 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <USSDDynMenuRequest> <requestId>$requestId</requestId>" <sessionId name='sessionId'>$sessionId</sessionId> <msisdn name='msisdn'>$msisdn</msisdn> <starCode name='starCode'>$starCode</starCode> <keyWord name='keyWord'>$keyWord</keyWord>" <dataSet> <param><id>$1</id><value>param1</value></param> <param><id>$2</id><value>param2</value></param> <param><id>$3</id><value>param3</value></param> <param><id>$4</id><value>param4</value></param> <param><id>$5</id><value>param5</value></param> </dataSet> <userData name="subRsp">$subRsp</userData> <timeStamp>$timestamp</timeStamp> </USSDDynMenuRequest> -
Lormenyo created this gist
Aug 14, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ package com.jaxb; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; public class ReadXml { public static void main(String[] args) throws IOException { File xmlFile = new File("ussd.xml"); unmarshalXML(xmlFile); marshalXML(); } //-------------------------- UNMARSHALLING XML ------------------------------------ public static void unmarshalXML(File xmlFile) { try { System.out.println("Unmarshalling XML to Java Object-------"); //creating the JAXB context JAXBContext jContext = JAXBContext.newInstance(USSDDynMenuRequest.class); //creat the unmarshal object Unmarshaller unmarshallerObj = jContext.createUnmarshaller(); //call the unmarshal method USSDDynMenuRequest request= (USSDDynMenuRequest) unmarshallerObj.unmarshal(xmlFile); request.setStarCode("124"); request.setKeyWord("Start"); System.out.println(request.getStarCode() + " " + request.getKeyWord() ); } catch(Exception e){ e.printStackTrace(); } } //-------------------------- MARSHALLING XML ------------------------------------ public static void marshalXML() { try { System.out.println("Marshalling Java Object to XML-------"); //creating the JAXB context JAXBContext jContext = JAXBContext.newInstance(USSDDynMenuRequest.class); //create the marshaller object Marshaller marshallerObj = jContext.createMarshaller(); //set the property to show xml format output marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); USSDDynMenuRequest Sendrequest= new USSDDynMenuRequest(); Sendrequest.setStarCode("124"); Sendrequest.setKeyWord("Start"); Sendrequest.setRequestId("1"); Sendrequest.setMsisdn("0244708099"); Sendrequest.setSessionId("789888886adh"); Sendrequest.setSubRsp("Balance"); //calling the marshall method marshallerObj.marshal(Sendrequest, new FileOutputStream("response.xml")); } catch(Exception e){ e.printStackTrace(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ package com.jaxb; //import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; // The POJO class @XmlRootElement(name="USSDDynMenuRequest") public class USSDDynMenuRequest{ private String requestId; private String sessionId; private String msisdn; private String starCode; private String keyWord; private String timeStamp; private String subRsp; public String getRequestId(){ return requestId; } @XmlElement public void setRequestId(String requestId){ this.requestId = requestId; } @XmlElement(name="sessionId") public void setSessionId(String sessionId){ this.sessionId = sessionId; } public String getSessionId(){ return sessionId; } public String getMsisdn(){ return msisdn; } @XmlElement(name="msisdn") public void setMsisdn(String msisdn){ this.msisdn = msisdn; } @XmlElement(name="starCode") public void setStarCode(String starCode){ this.starCode = starCode; } public String getStarCode(){ return starCode; } @XmlElement(name="keyWord") public void setKeyWord(String keyWord){ this.keyWord = keyWord; } public String getKeyWord(){ return keyWord; } public String getTimeStamp(){ return timeStamp; } @XmlElement(name="subRsp") public void setSubRsp(String subRsp){ this.subRsp = subRsp; } public String getSubRsp(){ return subRsp; } }