protected void writeXML() throws XMLStreamException, JsonParseException, IOException
	{
		XMLOutputFactory factory      = XMLOutputFactory.newInstance();
		JsonFactory jsonF = new JsonFactory();
		XMLStreamWriter writer = null;
		JsonParser jp = null;
		try {
			jp = jsonF.createJsonParser(is);
			writer =  factory.createXMLStreamWriter(os);
			
			
			if (jp.nextToken() != JsonToken.START_OBJECT) {
			    throw new IOException("Expected data to start with an Object");
			}
			writer.writeStartDocument();
			while ((jp.nextToken() != null))
			{
				String fieldName = jp.getCurrentName();
				   // Let's move to value
				jp.nextToken();//value or start_object or start_array
				
				if ("rows".equals(fieldName))
				{
					writer.writeStartElement("entities");
					jp.nextToken();//start object, start array was taken care by prev nextToken() call
					String currentEntityId = null;
					while(jp.nextToken() != JsonToken.END_OBJECT) //reads the key
					{
						String keyName = jp.getCurrentName();
						jp.nextToken();//value or start_object or start_array
						if("key".equals(keyName))
						{
							String entityId = jp.getText();
							if(currentEntityId != null && !currentEntityId.equals(entityId))
							{
								currentEntityId = entityId;
								writer.writeEndElement();
								writer.writeStartElement("entity");
								writer.writeAttribute("id", entityId);
							}
							else if(currentEntityId == null)
							{
								currentEntityId = entityId;
								writer.writeStartElement("entity");
								writer.writeAttribute("id", entityId);
							}
						}
						else if("value".equals(keyName))
						{
							Map<String, Object> row = new LinkedHashMap<String, Object>(); 
							readJsonObject(jp, row);
							writeXMLObject(writer, row, "document", "entity");
							jp.nextToken(); //move it off the END_OBJECT
							jp.nextToken(); //move it off the END_OBJECT
						}
					}
					//Close array for the last entityId
					writer.writeEndElement();
					writer.writeEndElement();
				}
				
	
			}
//		    writer.writeEndElement();
		    writer.writeEndDocument();
		 }
		 finally
		 {
			 writer.flush();
			 writer.close();
		 }

	}