当前位置: 首页>>代码示例>>Java>>正文


Java XmlPullParserFactory.newSerializer方法代码示例

本文整理汇总了Java中org.xmlpull.v1.XmlPullParserFactory.newSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java XmlPullParserFactory.newSerializer方法的具体用法?Java XmlPullParserFactory.newSerializer怎么用?Java XmlPullParserFactory.newSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xmlpull.v1.XmlPullParserFactory的用法示例。


在下文中一共展示了XmlPullParserFactory.newSerializer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toXml

import org.xmlpull.v1.XmlPullParserFactory; //导入方法依赖的package包/类
/**
 * To XML.
 *
 * @param outputStream
 *            the output stream.
 * @throws Exception
 *             a generic exception.
 */
public void toXml(OutputStream outputStream) throws Exception {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    XmlSerializer xs = factory.newSerializer();
    xs
            .setProperty(
                    "http://xmlpull.org/v1/doc/properties.html#serializer-indentation",
                    "  ");

    xs.setOutput(outputStream, "UTF-8");

    // first write XML declaration
    xs.startDocument("UTF-8", null);
    // add some empty lines before first start tag
    xs.ignorableWhitespace("\n");

    toXml(xs);

    xs.endDocument();
}
 
开发者ID:dvorka,项目名称:mindraider,代码行数:28,代码来源:Resource.java

示例2: testSerializeBeyondBmpToOutputStream

import org.xmlpull.v1.XmlPullParserFactory; //导入方法依赖的package包/类
public void testSerializeBeyondBmpToOutputStream() throws XmlPullParserException, IOException {
    final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    final XmlSerializer serializer = factory.newSerializer();

    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    serializer.setOutput(os, "utf-8");

    checkSerializeBeyondBmp(serializer);

    assertEquals(EXPECTED_XML_SERIALIZATION, os.toString("utf-8"));
}
 
开发者ID:stefanhaustein,项目名称:kxml2,代码行数:13,代码来源:TestWb.java

示例3: testSerializeBeyondBmpToWriter

import org.xmlpull.v1.XmlPullParserFactory; //导入方法依赖的package包/类
public void testSerializeBeyondBmpToWriter() throws XmlPullParserException, IOException {
    final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    final XmlSerializer serializer = factory.newSerializer();

    final StringWriter writer = new StringWriter();
    serializer.setOutput(writer);

    checkSerializeBeyondBmp(serializer);

    assertEquals(EXPECTED_XML_SERIALIZATION, writer.toString());
}
 
开发者ID:stefanhaustein,项目名称:kxml2,代码行数:13,代码来源:TestWb.java

示例4: createXmlSerializer

import org.xmlpull.v1.XmlPullParserFactory; //导入方法依赖的package包/类
public static XmlSerializer createXmlSerializer(Writer out) {
	XmlSerializer result = null;
	try {
		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		factory.setValidating(true);
		result = factory.newSerializer();
		result.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
		result.setOutput(out);
	} catch (Exception e) {
		log.error("When creating XmlSerializer: " + e.getClass().getName() + ": " + e.getMessage());
	}
	return result;
}
 
开发者ID:finanzer,项目名称:epubfx,代码行数:14,代码来源:EpubProcessorSupport.java

示例5: loadOUIAndmakeXml

import org.xmlpull.v1.XmlPullParserFactory; //导入方法依赖的package包/类
private static void loadOUIAndmakeXml(final String source) throws IOException, XmlPullParserException {
    
    final String NAMESPACE = "http://standards-oui.ieee.org/oui.txt";
    
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
            System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
    XmlSerializer serializer = factory.newSerializer();
    
    BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(source)));
    BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(VENDOR_MACS_PATH)));
    String tmp = null;
    
    // xml
    serializer.setOutput(bfw);
    serializer.startDocument(null, Boolean.valueOf(true));
    serializer.ignorableWhitespace("\n");
    serializer.comment(bfr.readLine());
    serializer.ignorableWhitespace("\n");
    
    serializer.setPrefix("", NAMESPACE);
    serializer.startTag(NAMESPACE, "MacAddressVendorMappings");
    //serializer.text("\n");
    
    while ( (tmp = bfr.readLine()) != null) {
        if (tmp.contains(DELIM) == false)
            continue;
        
        StringTokenizer stk = new StringTokenizer(tmp.replace(DELIM, "="), EQUAL);
        String prefix = null;
        String vendor = null;
        
        if (stk.hasMoreTokens())
            prefix = stk.nextToken().trim();
        
        if (stk.hasMoreTokens())
            vendor = stk.nextToken().trim();
        
        // xml attribute
        writeLine(serializer, prefix, vendor);
    }
    
    serializer.endTag(NAMESPACE, "MacAddressVendorMappings");
    serializer.endDocument();
    
    //write xml data into the FileOutputStream
    serializer.flush();
    
    bfr.close();
    bfw.close();
    
    System.out.println("Done!!!, File generated : " + VENDOR_MACS_PATH);
}
 
开发者ID:blomdhal22,项目名称:vendormac,代码行数:53,代码来源:VendorMac.java


注:本文中的org.xmlpull.v1.XmlPullParserFactory.newSerializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。