android.util.Xml.newSerializer()方法的使用及代码示例

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

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

Xml.newSerializer介绍

暂无

代码示例

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

private String serialize(Element e, int intent){
  
  try{
  
    XmlSerializer s = Xml.newSerializer();
    StringWriter sw = new StringWriter();
  
    s.setOutput(sw);
    s.startDocument("utf-8", null);
    
    String spaces = null;
    if(intent > 0){
      char[] chars = new char[intent];
      Arrays.fill(chars, ' ');
      spaces = new String(chars);
    }
    
    serialize(root, s, 0, spaces);
    s.endDocument();
    
    return sw.toString();
  }catch(Exception ex){
    ex.printStackTrace();
  }
  
  return null;
}

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

public static String serialize(Set<String> set) {
  if (set == null) {
    set = Collections.emptySet();
  }
  StringWriter writer = new StringWriter();
  XmlSerializer serializer = Xml.newSerializer();
  try {
    serializer.setOutput(writer);
    serializer.startTag(NAMESPACE, SET_TAG);
    for (String string : set) {
      serializer.startTag(NAMESPACE, STRING_TAG) //
          .text(string) //
          .endTag(NAMESPACE, STRING_TAG);
    }
    serializer.endTag(NAMESPACE, SET_TAG) //
        .endDocument();
  } catch (IllegalArgumentException | IOException | IllegalStateException e) {
    // should never happen
  }
  return writer.toString();
}

代码示例来源:origin: evernote/android-job

/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static final void writeListXml(List val, OutputStream out)
    throws XmlPullParserException, java.io.IOException {
  XmlSerializer serializer = Xml.newSerializer();
  serializer.setOutput(out, "utf-8");
  serializer.startDocument(null, true);
  serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
  writeListXml(val, null, serializer);
  serializer.endDocument();
}

代码示例来源:origin: k9mail/k-9

XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(os, "UTF-8");

代码示例来源:origin: google/ExoPlayer

throws XmlPullParserException, IOException {
scratchOutputStream.reset();
XmlSerializer xmlSerializer = Xml.newSerializer();
xmlSerializer.setOutput(scratchOutputStream, C.UTF8_NAME);

代码示例来源:origin: posm/OpenMapKitAndroid

private OSMXmlWriter(LinkedList<OSMElement> elements, String generator, String osmUser) {
  this.elements = elements;
  this.generator = generator;
  this.osmUser = osmUser;
  xmlSerializer = Xml.newSerializer();
  stringWriter = new StringWriter();
}

代码示例来源:origin: org.apache.chemistry.opencmis/chemistry-opencmis-android-client

/**
 * Creates a new XML writer.
 */
public static XmlSerializer createWriter(OutputStream out) throws IOException {
  assert out != null;
  XmlSerializer writer = Xml.newSerializer();
  writer.setOutput(out, IOUtils.UTF8);
  
  return writer;
}

代码示例来源:origin: Azure/azure-storage-android

/**
 * Returns a <code>XmlSerializer</code> which outputs to the specified <code>StringWriter</code>
 * 
 * @param outWriter
 *            the <code>StringWriter</code> to output to
 * @return A <code>XmlSerializer</code> instance
 * 
 * @throws IOException
 *             if there is an error setting the output.
 * @throws IllegalStateException
 *             if there is an error setting the output.
 * @throws IllegalArgumentException
 *             if there is an error setting the output.
 */
public static XmlSerializer getXmlSerializer(StringWriter outWriter) throws IllegalArgumentException,
    IllegalStateException, IOException {
  XmlSerializer serializer = Xml.newSerializer();
  serializer.setOutput(outWriter);
  return serializer;
}

代码示例来源:origin: com.googlecode.android-query/android-query

private String serialize(Element e, int intent){
  
  try{
  
    XmlSerializer s = Xml.newSerializer();
    StringWriter sw = new StringWriter();
  
    s.setOutput(sw);
    s.startDocument("utf-8", null);
    
    String spaces = null;
    if(intent > 0){
      char[] chars = new char[intent];
      Arrays.fill(chars, ' ');
      spaces = new String(chars);
    }
    
    serialize(root, s, 0, spaces);
    s.endDocument();
    
    return sw.toString();
  }catch(Exception ex){
    ex.printStackTrace();
  }
  
  return null;
}

代码示例来源:origin: com.facebook.testing.screenshot/core

private void initXml() {
 if (mOutputStream != null) {
  return;
 }
 try {
  mOutputStream = new FileOutputStream(getMetadataFile());
  mXmlSerializer = Xml.newSerializer();
  mXmlSerializer.setOutput(mOutputStream, "utf-8");
  mXmlSerializer.startDocument("utf-8", null);
  mXmlSerializer.startTag(null, "screenshots");
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: org.androidannotations/androidannotations-api

public static String serialize(Set<String> set) {
  if (set == null) {
    set = Collections.emptySet();
  }
  StringWriter writer = new StringWriter();
  XmlSerializer serializer = Xml.newSerializer();
  try {
    serializer.setOutput(writer);
    serializer.startTag(NAMESPACE, SET_TAG);
    for (String string : set) {
      serializer.startTag(NAMESPACE, STRING_TAG) //
          .text(string) //
          .endTag(NAMESPACE, STRING_TAG);
    }
    serializer.endTag(NAMESPACE, SET_TAG) //
        .endDocument();
  } catch (IllegalArgumentException | IOException | IllegalStateException e) {
    // should never happen
  }
  return writer.toString();
}

代码示例来源:origin: mkulesh/microMathematics

private String getArrayName(final List<Element> prevElements, int args) throws Exception
{
  ArrayList<Element> elements = new ArrayList<>(prevElements.size());
  elements.addAll(prevElements);
  if (args > 1)
  {
    final StringWriter writer = new StringWriter();
    final XmlSerializer serializer = Xml.newSerializer();
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    serializer.setOutput(writer);
    serializer.startDocument("UTF-8", true);
    parseTermArguments(args - 1, elements, serializer);
    serializer.endDocument();
  }
  final Element last = XmlUtils.getLast(elements);
  if (last != null)
  {
    ExpressionProperties p = new ExpressionProperties(last);
    if (p.isOperand())
    {
      return p.text;
    }
  }
  return "";
}

代码示例来源:origin: jruesga/rview

private static CharSequence writeSvg(Context ctx, Vector vector) {
  if (vector != null) {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      XmlSerializer serializer = Xml.newSerializer();
      serializer.setOutput(writer);
      serializer.startTag(SVG_NAMESPACE, "svg");
      serializer.attribute(SVG_NAMESPACE, "width",
          String.format(Locale.US, "%f", vector.mWidth));
      serializer.attribute(SVG_NAMESPACE, "height",
          String.format(Locale.US, "%f", vector.mHeight));
      serializer.attribute(SVG_NAMESPACE, "viewBox",
          String.format(Locale.US, "0 0 %f %f", vector.mWidth, vector.mHeight));
      for (Group group : vector.mGroups)  {
        serializeGroup(ctx, serializer, vector, group);
      }
      for (Path path : vector.mPaths)  {
        serializePath(ctx, serializer, path);
      }
      serializer.endTag(SVG_NAMESPACE, "svg");
      serializer.endDocument();
      serializer.flush();
      return writer.toString();
    } catch (Exception ex) {
      Log.e(TAG, "Can't write svg xml", ex);
    }
  }
  return null;
}

代码示例来源:origin: gdpancheng/LoonAndroid3

private static String getXml(LinkedHashMap<String, Object> data, String method, String name_space) {
  XmlSerializer serializer = Xml.newSerializer();
  StringWriter writer = new StringWriter();
  try {

代码示例来源:origin: SimonMarquis/Android-PreferencesManager

/**
 * Flatten a List into an output stream as XML. The list can later be read
 * back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static final void writeListXml(List val, OutputStream out) throws XmlPullParserException, java.io.IOException {
  XmlSerializer serializer = Xml.newSerializer();
  serializer.setOutput(out, "utf-8");
  serializer.startDocument(null, true);
  serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
  writeListXml(val, null, serializer);
  serializer.endDocument();
}

代码示例来源:origin: henrichg/PhoneProfilesPlus

/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static final void writeListXml(List val, OutputStream out)
    throws XmlPullParserException, java.io.IOException {
  XmlSerializer serializer = Xml.newSerializer();
  serializer.setOutput(out, "utf-8");
  serializer.startDocument(null, true);
  serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
  writeListXml(val, null, serializer);
  serializer.endDocument();
}

代码示例来源:origin: xuyisheng/TextViewForFullHtml

/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static final void writeListXml(List val, OutputStream out)
    throws XmlPullParserException, IOException {
  XmlSerializer serializer = Xml.newSerializer();
  serializer.setOutput(out, "utf-8");
  serializer.startDocument(null, true);
  serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
  writeListXml(val, null, serializer);
  serializer.endDocument();
}

代码示例来源:origin: 18Gray/CommonUtils

/**
 * 特定对象转xml文件实例
 * @param persons
 * @param out
 * @throws Exception
 */
public static void pojo2String(List<Person> persons, OutputStream out) throws Exception
{
  XmlSerializer serializer = Xml.newSerializer();
  serializer.setOutput(out, "UTF-8");
  serializer.startDocument("UTF-8", true);
  serializer.startTag(null, "persons");
  for (Person person : persons)
  {
    serializer.startTag(null, "person");
    serializer.attribute(null, "id", person.getId().toString());
    serializer.startTag(null, "name");
    serializer.text(person.getName().toString());
    serializer.endTag(null, "name");
    serializer.startTag(null, "age");
    serializer.text(person.getAge().toString());
    serializer.endTag(null, "age");
    serializer.endTag(null, "person");
  }
  serializer.endTag(null, "persons");
  serializer.endDocument();
  out.flush();
  out.close();
}

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

static boolean parseToXml(ApplicationList applications, OutputStream out) {
  XmlSerializer serializer = Xml.newSerializer();
  try {
    serializer.setOutput(out, "UTF-8");
    serializer.startTag(ns, "fdroid");
    for (ApplicationDetails app : applications) {
      serializer.startTag(ns, "application");
      writeTag(serializer, ID, app.getPackageName());
      writeTag(serializer, LAST_UPDATED, app.getLastUpdatedDateString());
      writeTag(serializer, NAME, app.getProjectName());
      writeTag(serializer, DESCRIPTION, app.getDescription());
      writeTag(serializer, ICON_URL, app.getIconUrl());
      writeTag(serializer, SOURCE_URL, app.getSourceCodeUrl());
      writeTag(serializer, WEB, app.getProjectWebUrl());
      writeTag(serializer, MAIL, app.getProjectMail());
      serializer.endTag(ns, "application");
    }
    serializer.endTag(ns, "fdroid");
    serializer.flush();
    return true;
  } catch (IOException e) {
    e.printStackTrace();
    return false;
  }
}

代码示例来源:origin: nbenm/ImapNote2

public void SaveConfigurationToXML() throws IllegalArgumentException, IllegalStateException, IOException{
  FileOutputStream configurationFile = this.applicationContext.openFileOutput("ImapNotes2.conf", Context.MODE_PRIVATE);
  XmlSerializer serializer = Xml.newSerializer();
  serializer.setOutput(configurationFile, "UTF-8");
  serializer.startDocument(null, Boolean.valueOf(true));

相关文章