zoukankan      html  css  js  c++  java
  • xml

    package com.leileixml;

    import java.io.FileWriter;
    import java.io.IOException;

    import org.xmlpull.v1.XmlPullParserFactory;
    import org.xmlpull.v1.XmlSerializer;

    public class PullSerializae {
    public static void main(String[] args) throws Exception {
    //创建解析器工厂对象
    XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();

    //2.创建序列化器对象
    XmlSerializer serializer = parserFactory.newSerializer();

    //3.指定文件存放的路径
    serializer.setOutput(new FileWriter("xml2.xml"));

    serializer.startDocument("GB2312", false);//文档开始
    serializer.startTag(null, "students");//根标记开始
    serializer.startTag(null, "student");//student子标记开始
    serializer.startTag(null, "xh");//id子标记开始
    serializer.text("1234345");//标记内容
    serializer.endTag(null, "xh");//id子标记结束
    serializer.startTag(null, "name");//name字标记开始
    serializer.text("阿拉蕾");
    serializer.endTag(null, "name");//name子标记结束
    serializer.startTag(null, "age");//age字标记开始
    serializer.text("19");
    serializer.endTag(null, "age");//age子标记结束
    serializer.startTag(null, "sex");//sex子标记开始
    serializer.text("女");
    serializer.endTag(null, "sex");//sex子标记结束
    serializer.endTag(null, "student");//student子标记结束
    serializer.startTag(null, "student");
    serializer.attribute(null, "xh", "1314520");//命名空间、属性名、属性值
    serializer.attribute(null, "name", "王明雷");//命名空间、属性名、属性值
    serializer.attribute(null, "age", "26");//命名空间、属性名、属性值
    serializer.attribute(null, "sex"," 男");//命名空间、属性名、属性值
    serializer.endTag(null, "student");
    serializer.endTag(null, "students");

    serializer.endDocument();
    }


    }

  • 相关阅读:
    [BUUOJ记录] [强网杯 2019]随便注(三种方法)
    Content Security Policy (CSP)内容安全策略总结
    [HGAME Week2] Cosmos的博客后台
    [BUUOJ记录] [ACTF2020 新生赛]Include
    PHP弱类型hash比较缺陷
    CTF常见源码泄漏总结
    Sqlmap Tamper绕过脚本详解
    Golden Pyramid
    Prime Palindrome Golf
    Min and Max
  • 原文地址:https://www.cnblogs.com/2410164885qq/p/6386828.html
Copyright © 2011-2022 走看看