org.xmlpull.v1.XmlPullParserFactory.newSerializer()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.xmlpull.v1.XmlPullParserFactory.newSerializer()方法的一些代码示例,展示了XmlPullParserFactory.newSerializer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlPullParserFactory.newSerializer()方法的具体详情如下:
包路径:org.xmlpull.v1.XmlPullParserFactory
类名称:XmlPullParserFactory
方法名:newSerializer

XmlPullParserFactory.newSerializer介绍

[英]Creates a new instance of a XML Serializer.

NOTE: factory features are not used for XML Serializer.
[中]创建XML序列化程序的新实例。
注意:工厂特性不用于XML序列化程序。

代码示例

代码示例来源:origin: me.tatarka.parsnip/parsnip

/**
 * Creates a new xml serializer.
 */
private static XmlSerializer newSerializer() {
  try {
    return XmlSerializerFactory.instance.newSerializer();
  } catch (XmlPullParserException e) {
    throw new AssertionError(e);
  }
}

代码示例来源:origin: com.google.http-client/google-http-client-xml

/**
 * Returns a new XML serializer.
 *
 * @throws IllegalArgumentException if encountered an {@link XmlPullParserException}
 */
public static XmlSerializer createSerializer() {
 try {
  return getParserFactory().newSerializer();
 } catch (XmlPullParserException e) {
  throw new IllegalArgumentException(e);
 }
}

代码示例来源:origin: xpp3/xpp3

public XmlSerializerWrapper newSerializerWrapper() throws XmlPullParserException {
  XmlSerializer xs = f.newSerializer();
  return new StaticXmlSerializerWrapper(xs, this);
}

代码示例来源:origin: org.ogce/xpp3

public XmlSerializerWrapper newSerializerWrapper() throws XmlPullParserException {
  XmlSerializer xs = f.newSerializer();
  return new StaticXmlSerializerWrapper(xs, this);
}

代码示例来源:origin: org.seamless/seamless-xml

static public XmlSerializer createSerializer() throws XmlPullParserException {
  if (xmlPullParserFactory == null) throw new XmlPullParserException("no XML Pull parser factory");
  return xmlPullParserFactory.newSerializer();
}

代码示例来源:origin: com.uphyca/android-junit4

private XmlSerializer newSerializer(Writer writer) {
  try {
    XmlPullParserFactory pf = XmlPullParserFactory.newInstance();
    XmlSerializer serializer = pf.newSerializer();
    serializer.setOutput(writer);
    return serializer;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: esmasui/AndroidJUnit4

private XmlSerializer newSerializer(Writer writer) {
  try {
    XmlPullParserFactory pf = XmlPullParserFactory.newInstance();
    XmlSerializer serializer = pf.newSerializer();
    serializer.setOutput(writer);
    return serializer;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: LonamiWebs/Stringlate

public boolean save() {
  if (mSavedChanges)
    return true;
  if (mFile == null)
    return false;
  try {
    if (!mFile.getParentFile().isDirectory())
      mFile.getParentFile().mkdirs();
    FileOutputStream out = new FileOutputStream(mFile);
    final XmlSerializer serializer = XmlPullParserFactory.newInstance().newSerializer();
    mSavedChanges = ResourcesParser.parseToXml(this, out, serializer);
    mModified = true;
    out.close();
  } catch (IOException | XmlPullParserException e) {
    e.printStackTrace();
  }
  // We do not want empty files, if it exists and it's empty delete it
  if (mFile.isFile() && mFile.length() == 0)
    mFile.delete();
  return mFile.isFile();
}

代码示例来源:origin: org.ogce/xpp3

public static void main(String [] args)
{
  // create an instance of RSSReader
  RSSReader rssreader = new RSSReader();
  try {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    XmlPullParser parser = factory.newPullParser();
    String url = args[0];
    InputStreamReader stream = new InputStreamReader(
      new URL(url).openStream());
    parser.setInput(stream);
    XmlSerializer writer = factory.newSerializer();
    writer.setOutput(new OutputStreamWriter(System.out));
    rssreader.convertRSSToHtml(parser, writer);
  } catch (Exception e) {
    e.printStackTrace(System.err);
  }
}

代码示例来源:origin: org.ogce/xpp3

private static void roundTrip(XmlPullParserFactory factory, String loc, String indent)
  throws XmlPullParserException, IOException
{
  XmlPullParser pp = factory.newPullParser();
  pp.setInput(new java.net.URL(loc).openStream(), null);
  
  XmlSerializer serializer = factory.newSerializer();
  serializer.setOutput( System.out, null);
  if(indent != null) {
    serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
  }
  (new Roundtrip(pp, serializer)).roundTrip();
}

代码示例来源:origin: org.robokind/org.robokind.extern.utils.xpp3

/**
 * Creates an XmlSerializer for writing XML to the given file.
 * @param path location to write the XML file
 * @return XmlSerializer for writing XML to the given file
 * @throws XmlPullParserException
 * @throws FileNotFoundException
 * @throws IOException
 */
public static XmlSerializer getXmlFileSerializer(String path) throws XmlPullParserException, FileNotFoundException, IOException{
  XmlPullParserFactory fact = XmlPullParserFactory.newInstance();
  XmlSerializer xs = fact.newSerializer();
  XMLUtils.format(xs, true);
  xs.setOutput(new FileWriter(path));
  return xs;
}

代码示例来源:origin: org.jflux/org.jflux.extern.utils.xpp3.rk

/**
 * Creates an XmlSerializer for writing XML to the given file.
 * @param path location to write the XML file
 * @return XmlSerializer for writing XML to the given file
 * @throws XmlPullParserException
 * @throws FileNotFoundException
 * @throws IOException
 */
public static XmlSerializer getXmlFileSerializer(String path) throws XmlPullParserException, FileNotFoundException, IOException{
  XmlPullParserFactory fact = XmlPullParserFactory.newInstance();
  XmlSerializer xs = fact.newSerializer();
  XMLUtils.format(xs, true);
  xs.setOutput(new FileWriter(path));
  return xs;
}

代码示例来源:origin: com.googlecode.linkedin-j/linkedin-j-core

/**
 * Method description
 *
 *
 * @param element
 *
 * @return
 */
protected String marshallObject(Object element) {
  if (element instanceof String) {
    return (String) element;
  } else if (element instanceof BaseSchemaEntity) {
    try {
      StringWriter writer = new StringWriter();
      XmlSerializer serializer = XmlPullParserFactory.newInstance().newSerializer();
      serializer.setOutput(writer);
      ((BaseSchemaEntity) element).toXml(serializer);
      serializer.flush();
      return writer.toString();
    } catch (Exception e) {
      throw new LinkedInApiClientException("Unkown element encountered:" + element, e);
    }
  } else {
    throw new LinkedInApiClientException("Unkown element encountered:" + element);
  }
}

代码示例来源:origin: org.apache.airavata/airavata-gfac-schema-utils

public static void roundTrip(Reader reader, Writer writer, String indent) throws XmlPullParserException,
    IOException {
  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  factory.setNamespaceAware(true);
  XmlPullParser pp = factory.newPullParser();
  pp.setInput(reader);
  XmlSerializer serializer = factory.newSerializer();
  serializer.setOutput(writer);
  if (indent != null) {
    serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
  }
  (new RoundTrip(pp, serializer)).roundTrip();
}

代码示例来源:origin: org.apache.airavata/gfac-schema-utils

public static void roundTrip(Reader reader, Writer writer, String indent) throws XmlPullParserException,
    IOException {
  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  factory.setNamespaceAware(true);
  XmlPullParser pp = factory.newPullParser();
  pp.setInput(reader);
  XmlSerializer serializer = factory.newSerializer();
  serializer.setOutput(writer);
  if (indent != null) {
    serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
  }
  (new RoundTrip(pp, serializer)).roundTrip();
}

代码示例来源:origin: org.ogce/xpp3

private static void roundTrip(Reader reader, Writer writer, String indent)
  throws XmlPullParserException, IOException
{
  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  factory.setNamespaceAware(true);
  XmlPullParser pp = factory.newPullParser();
  pp.setInput(reader);
  XmlSerializer serializer = factory.newSerializer();
  serializer.setOutput( writer );
  if(indent != null) {
    serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
  }
  (new Roundtrip(pp, serializer)).roundTrip();
  
}

代码示例来源:origin: westnordost/osmapi

@Override
public final void write(OutputStream out) throws IOException
{
  try
  {
    xml = XmlPullParserFactory.newInstance().newSerializer();
  }
  catch(XmlPullParserException e)
  {
    throw new RuntimeException("Cannot initialize serializer", e);
  }
  xml.setOutput(out, CHARSET);
  xml.startDocument(CHARSET, null);
  write();
  if(xml.getName() != null)
  {
    throw new IllegalStateException("Forgot to close a tag");
  }
  xml.endDocument();
  xml.flush();
}

代码示例来源:origin: xpp3/xpp3

/**
 * Serialize item to given writer.
 *
 * @param    item                an Object
 * @param    writer              a  Writer
 *
 * @exception   XmlBuilderException
 *
 */
public void serializeToWriter(Object item, //XmlContainer node,
               Writer writer)
  //throws XmlPullParserException, IOException, IllegalArgumentException
  throws XmlBuilderException
{
  XmlSerializer ser = null;
  try {
    ser = factory.newSerializer();
    ser.setOutput(writer);
  } catch (Exception e) {
    throw new XmlBuilderException("could not serialize node to writer", e);
  }
  serialize(item, ser);
  try {
    ser.flush();
  } catch (IOException e) {
    throw new XmlBuilderException("could not flush output", e);
  }
}

代码示例来源:origin: org.ogce/xpp3

/**
 * Serialize item to given writer.
 *
 * @param    item                an Object
 * @param    writer              a  Writer
 *
 * @exception   XmlBuilderException
 *
 */
public void serializeToWriter(Object item, //XmlContainer node,
               Writer writer)
  //throws XmlPullParserException, IOException, IllegalArgumentException
  throws XmlBuilderException
{
  XmlSerializer ser = null;
  try {
    ser = factory.newSerializer();
    ser.setOutput(writer);
  } catch (Exception e) {
    throw new XmlBuilderException("could not serialize node to writer", e);
  }
  serialize(item, ser);
  try {
    ser.flush();
  } catch (IOException e) {
    throw new XmlBuilderException("could not flush output", e);
  }
}

代码示例来源:origin: xpp3/xpp3

ser = factory.newSerializer();
  ser.setOutput(os, encoding);
} catch (Exception e) {

相关文章