本文整理汇总了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();
}
示例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"));
}
示例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());
}
示例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;
}
示例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);
}