當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。