Code example for XmlSerializer

Methods: endDocument, endTag, flush, setOutput, startDocument, startTag, text

0
		} 
	} 
 
    private void writeRecipeXML(XmlSerializer recipeSerializer, FileOutputStream output) {
        try { 
            recipeSerializer.setOutput(output, "UTF-8");
            recipeSerializer.startDocument(null, Boolean.valueOf(true));
            recipeSerializer.startTag(null, "recipe");
            addRecipeNode("name", nameString, recipeSerializer);
            addRecipeNode("hops", hopsString, recipeSerializer);
            addRecipeNode("malt", maltString, recipeSerializer);
            addRecipeNode("grain", grainString, recipeSerializer);
            addRecipeNode("directions", directionsString, recipeSerializer);
            recipeSerializer.endTag(null, "recipe");
            recipeSerializer.endDocument();
            recipeSerializer.flush();
 
        }catch( Exception e) {
            //Log.e("Exception","Exception occured in writing"); 
            e.printStackTrace();
        } 
    } 
     
    private void addRecipeNode(String tagName, String content, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
    	serializer.startTag(null, tagName);
        serializer.text(content);
        serializer.endTag(null, tagName);
    } 
 
	@Override 
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.