PULL generates XML files and pull generates xml files

Source: Internet
Author: User

PULL generates XML files and pull generates xml files

1 package xmlpulldemo; 2 3 import java. io. fileNotFoundException; 4 import java. io. fileOutputStream; 5 import java. io. IOException; 6 7 import org. xmlpull. v1.XmlPullParserException; 8 import org. xmlpull. v1.XmlPullParserFactory; 9 import org. xmlpull. v1.XmlSerializer; 10 11 public class PullProduceDocument {12 13 public static void main (String [] args) throws XmlPullParserException, IllegalArgumentException, 14 IllegalStateException, FileNotFoundException, IOException {15 16 // parser factory 17 XmlPullParserFactory factory = XmlPullParserFactory. newInstance (); 18 // serializer 19 XmlSerializer serializer = factory. newSerializer (); 20 // set the output location of the xml file 21 serializer. setOutput (new FileOutputStream ("src/books. xml ")," UTF-8 "); 22 // call the serialization method to write data into the xml file 23 serializer. startDocument ("UTF-8", true); 24 serializer. startTag (null, "books"); 25 for (int I = 0; I <5; I ++) {26 serializer. startTag (null, "book"); 27 serializer. attribute (null, "id", "book1"); 28 serializer. startTag (null, "name"); 29 serializer. text ("Romance of the Three Kingdoms"); 30 serializer. endTag (null, "name"); 31 serializer. startTag (null, "author"); 32 serializer. text ("Luo Guanzhong"); 33 serializer. endTag (null, "author"); 34 serializer. startTag (null, "price"); 35 serializer. text ("30 $"); 36 serializer. endTag (null, "price"); 37 serializer. endTag (null, "book"); 38} 39 serializer. endTag (null, "books"); 40 serializer. endDocument (); 41 42} 43 44}

 

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.