本文整理匯總了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);
}