Pull generate XML file

Source: Internet
Author: User

1  PackageXmlpulldemo;2 3 Importjava.io.FileNotFoundException;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 7 Importorg.xmlpull.v1.XmlPullParserException;8 Importorg.xmlpull.v1.XmlPullParserFactory;9 ImportOrg.xmlpull.v1.XmlSerializer;Ten  One  Public classpullproducedocument { A  -      Public Static voidMain (string[] args)throwsxmlpullparserexception, IllegalArgumentException, - illegalstateexception, FileNotFoundException, IOException { the  -         //Parser Factory -Xmlpullparserfactory factory =xmlpullparserfactory.newinstance (); -         //Serializer +XmlSerializer serializer =Factory.newserializer (); -         //set the output location of an XML file +Serializer.setoutput (NewFileOutputStream ("Src/books.xml"), "UTF-8"); A         //invoke the relevant method of the serializer to write data to the XML file atSerializer.startdocument ("UTF-8",true); -Serializer.starttag (NULL, "Books"); -          for(inti = 0; I < 5; i++) { -Serializer.starttag (NULL, "book"); -Serializer.attribute (NULL, "id", "Book1"); -Serializer.starttag (NULL, "name"); inSerializer.text ("Kingdoms"); -Serializer.endtag (NULL, "name"); toSerializer.starttag (NULL, "Author"); +Serializer.text ("Luo Guan Zhong"); -Serializer.endtag (NULL, "Author"); theSerializer.starttag (NULL, "Price"); *Serializer.text ("30$"); $Serializer.endtag (NULL, "Price");Panax NotoginsengSerializer.endtag (NULL, "book"); -         } theSerializer.endtag (NULL, "Books"); + serializer.enddocument (); A  the     } +  -}

Pull generate XML file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.