­

My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY





Free users please don't remove our link. Get the code again.

Saturday, March 8, 2014

Convert Object to XML String

 public String convertObjectToXmlString(ObjectClass theObjectClass)
   throws Exception {
  Marshaller triggerMarshaller = null;
  System.out.println("Converting String into XML");
  /** Anonymous Inner Class */
  OutputStream output = new OutputStream() {
   private StringBuilder string = new StringBuilder();

   @Override
   public void write(int b) throws IOException {
    this.string.append((char) b);
   }

   @Override
   public String toString() {
    return this.string.toString();
   }
  };

  JAXBContext jc = JAXBContext.newInstance("Your Package Name");
  triggerMarshaller = jc.createMarshaller();
  triggerMarshaller.marshal(triggerMessage, new StreamResult(output));
  return output.toString();

 }

No comments :