public static String createXMLSensorRecordInfo(List<String> fields) {
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();

    try {
      serializer.setOutput(writer);
      serializer.startDocument("UTF-8", false);

      final String nns = null; // no namespace
      final String ns = "urn:schemas-upnp-org:smgt:srecinfo";

      serializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
      serializer.setPrefix("", ns);
      serializer.startTag(ns, XMLSENSORRECORDINFO);
      serializer.attribute(
          "http://www.w3.org/2001/XMLSchema-instance",
          "schemaLocation",
          "urn:schemas-upnp-org:smgt:srecinfo http://www.upnp.org/schemas/ds/drecs-v1.xsd");

      serializer.startTag(nns, XMLSENSORRECORD);
      for (String field : fields) {

        serializer.startTag(nns, XMLFIELD);
        serializer.attribute(nns, XMLNAME, field);
        serializer.endTag(nns, XMLFIELD);
      }
      serializer.endTag(nns, XMLSENSORRECORD);
      serializer.endTag(ns, XMLSENSORRECORDINFO);
      serializer.endDocument();
      return writer.toString();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  public static synchronized String createXMLContentPathList(List<String> paths) {
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();

    try {
      serializer.setOutput(writer);
      serializer.startDocument("UTF-8", false);

      final String nns = null; // no namespace
      final String ns = "urn:schemas-upnp-org:dm:cms";

      serializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
      serializer.setPrefix("cms", ns);

      serializer.startTag(ns, XMLCONTENTPATHLIST);
      serializer.attribute(
          "http://www.w3.org/2001/XMLSchema-instance",
          "schemaLocation",
          "urn:schemas-upnp-org:dm:cms http://www.upnp.org/schemas/dm/cms.xsd");

      for (String path : paths) {
        serializer.startTag(nns, XMLCONTENTPATH);
        serializer.text(path);
        serializer.endTag(nns, XMLCONTENTPATH);
      }

      serializer.endTag(ns, XMLCONTENTPATHLIST);

      serializer.endDocument();
      return writer.toString();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * Write an EPUB 3.0 OPF package document.
   *
   * @param book the book to write the package document for
   * @param serializer the XML serialiser to write the package document to
   * @throws IOException if an I/O error occurs
   */
  public static void write(final XmlSerializer serializer, final Book book) throws IOException {
    Identifier bookId = book.getMetadata().getBookIdIdentifier();

    serializer.startDocument(Constants.CHARACTER_ENCODING, false);

    serializer.setPrefix(PREFIX_OPF, NAMESPACE_OPF);
    serializer.setPrefix(PREFIX_DUBLIN_CORE, NAMESPACE_DUBLIN_CORE);

    serializer.startTag(NAMESPACE_OPF, OPFElements.PACKAGE);
    serializer.attribute(PREFIX_EMPTY, OPFAttributes.VERSION, VERSION);
    serializer.attribute(
        PREFIX_EMPTY, OPFAttributes.UNIQUE_IDENTIFIER, bookId != null ? bookId.getId() : BOOK_ID);

    PackageDocumentMetadataWriter.writeMetaData(book, serializer);

    writeManifest(serializer, book);
    writeSpine(serializer, book);
    writeGuide(serializer, book);

    serializer.endTag(NAMESPACE_OPF, OPFElements.PACKAGE);

    serializer.endDocument();

    serializer.flush();
  }
 private String createSoapRequest(HashMap<String, String> requestFields) {
   XmlSerializer serializer = Xml.newSerializer();
   StringWriter writer = new StringWriter();
   try {
     serializer.setOutput(writer);
     serializer.setPrefix(SOAPENV, ENV);
     serializer.setPrefix(URN_STRING, URN);
     serializer.startTag(ENV, ENVELOPE);
     serializer.startTag(ENV, HEADER);
     serializer.startTag(URN, SESSION_HEADER);
     serializer.startTag(URN, SESSION_ID);
     serializer.text(requestFields.get(SESSION_ID));
     serializer.endTag(URN, SESSION_ID);
     serializer.endTag(URN, SESSION_HEADER);
     serializer.startTag(ENV, CALLOPTIONS);
     serializer.startTag(URN, CLIENT);
     serializer.text(requestFields.get(CLIENT));
     serializer.endTag(URN, CLIENT);
     serializer.endTag(ENV, CALLOPTIONS);
     serializer.endTag(ENV, HEADER);
     serializer.startTag(ENV, BODY);
     serializer.startTag(URN, LOGOUT);
     serializer.endTag(URN, LOGOUT);
     serializer.endTag(ENV, BODY);
     serializer.endTag(ENV, ENVELOPE);
     serializer.endDocument();
     return writer.toString();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  public static String createXMLDataStoreTableInfo(DataTableInfo datatable, boolean omitID) {

    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();
    if (datatable != null) {
      try {
        serializer.setOutput(writer);
        serializer.startDocument("UTF-8", false);
        final String nns = null; // no namespace
        final String ns = "urn:schemas-upnp-org:ds:dtinfo";

        serializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        serializer.setPrefix("", ns);
        serializer.startTag(ns, XMLDATATABLEINFO);
        serializer.attribute(
            "http://www.w3.org/2001/XMLSchema-instance",
            "schemaLocation",
            "urn:schemas-upnp-org:ds:dtinfo http://www.upnp.org/schemas/ds/dtinfo.xsd");

        if (omitID) {
          serializer.attribute(nns, XMLTABLEGUID, "");
          serializer.attribute(nns, XMLTABLEUPDATEID, "");
        } else {
          serializer.attribute(nns, XMLTABLEGUID, Integer.toString(datatable.getTableID()));
          serializer.attribute(nns, XMLTABLEUPDATEID, Integer.toString(datatable.getUpdateID()));
        }
        serializer.attribute(nns, XMLTABLEGRN, datatable.getURN());

        DataItemInfo[] di = datatable.getDataItemInfoList();
        if (di.length != 0) serializer.startTag(nns, XMLDATARECORD);
        for (int i = 0; i < di.length; i++) {
          serializer.startTag(nns, XMLFIELD);

          serializer.attribute(nns, XMLFNAME, di[i].getFieldName());
          serializer.attribute(nns, XMLFTYPE, di[i].getFieldType());
          serializer.attribute(nns, XMLFENCODING, di[i].getEncoding());
          // serializer.attribute(nns, XMLFREQUIRED, Boolean.toString((di[i].isRequired())));
          serializer.attribute(nns, XMLFREQUIRED, (di[i].isRequired()) ? "1" : "0");
          serializer.attribute(nns, XMLFNAMESPACE, di[i].getNamespace());
          // serializer.attribute(nns, XMLFTABLEPROP, Boolean.toString((di[i].isTableProp())));
          serializer.attribute(nns, XMLFTABLEPROP, (di[i].isTableProp()) ? "1" : "0");

          serializer.endTag(nns, XMLFIELD);
        }
        if (di.length != 0) serializer.endTag(nns, XMLDATARECORD);

        serializer.endTag(ns, XMLDATATABLEINFO);
        serializer.endDocument();
        return writer.toString();
      } catch (Exception e) {
        Log.e(TAG, "Error generating XML in createXMLDataStoreTableInfo: " + e);
      }
    }
    return "";
  }
Beispiel #6
0
  private void serializeTrack(Uri trackUri, XmlSerializer serializer)
      throws IllegalArgumentException, IllegalStateException, IOException {
    if (isCancelled()) {
      throw new IOException("Fail to execute request due to canceling");
    }
    serializer.startDocument("UTF-8", true);
    serializer.setPrefix("xsi", NS_SCHEMA);
    serializer.setPrefix("gpx10", NS_GPX_10);
    serializer.setPrefix("ogt10", NS_OGT_10);
    serializer.text("\n");
    serializer.startTag("", "gpx");
    serializer.attribute(null, "version", "1.1");
    serializer.attribute(null, "creator", "rp.android.gpstracker");
    serializer.attribute(
        NS_SCHEMA, "schemaLocation", NS_GPX_11 + " http://www.topografix.com/gpx/1/1/gpx.xsd");
    serializer.attribute(null, "xmlns", NS_GPX_11);

    // <metadata/> Big header of the track
    serializeTrackHeader(mContext, serializer, trackUri);

    // <wpt/> [0...] Waypoints
    if (includeAttachments) {
      serializeWaypoints(mContext, serializer, Uri.withAppendedPath(trackUri, "/media"));
    }

    // <trk/> [0...] Track
    serializer.text("\n");
    serializer.startTag("", "trk");
    serializer.text("\n");
    serializer.startTag("", "name");
    serializer.text(mName);
    serializer.endTag("", "name");
    // The list of segments in the track
    serializeSegments(serializer, Uri.withAppendedPath(trackUri, "segments"));
    serializer.text("\n");
    serializer.endTag("", "trk");

    serializer.text("\n");
    serializer.endTag("", "gpx");
    serializer.endDocument();
  }
Beispiel #7
0
 protected void readElement(XmlSerializer out, boolean includeOuterTag)
     throws XmlParseException, XmlPullParserException, IOException {
   XmlPullParser in = getParser();
   if (in.getEventType() != START_TAG) {
     throw new XmlParseException(in, "start tag expected");
   }
   if (out != null && includeOuterTag) {
     out.startTag(in.getNamespace(), in.getName());
   }
   int depth = 1;
   while (depth != 0) {
     switch (in.next()) {
       case START_TAG:
         if (out != null) {
           out.setPrefix("", in.getNamespace());
           out.startTag(in.getNamespace(), in.getName());
           for (int i = 0; i < in.getAttributeCount(); i++) {
             String attributeNamespace = in.getAttributeNamespace(i);
             String attributeName = in.getAttributeName(i);
             String attributeValue = in.getAttributeValue(i);
             out.attribute(attributeNamespace, attributeName, attributeValue);
           }
         }
         depth++;
         break;
       case END_TAG:
         if (out != null && (includeOuterTag || depth > 1)) {
           out.endTag(in.getNamespace(), in.getName());
         }
         depth--;
         break;
       case TEXT:
         if (out != null) {
           out.text(in.getText());
         }
         break;
       case CDSECT:
         if (out != null) {
           out.cdsect(in.getText());
         }
         break;
       case ENTITY_REF:
         if (out != null) {
           out.entityRef(in.getText());
         }
         break;
     }
   }
   if (out != null) {
     out.flush();
   }
 }
  // TODO: copy from deviceLib parsing, where DataRecordInfo structs is used to support
  // dataTypeEnable
  public static String createXMLDataRecords(HashMap<String, String> fieldValues) {
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();

    try {
      serializer.setOutput(writer);
      serializer.startDocument("UTF-8", false);

      final String nns = null; // no namespace
      final String ns = "urn:schemas-upnp-org:ds:drecs";

      serializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
      serializer.setPrefix("", ns);
      serializer.startTag(ns, XMLDATARECORDS);
      serializer.attribute(
          "http://www.w3.org/2001/XMLSchema-instance",
          "schemaLocation",
          "urn:schemas-upnp-org:ds:drecs http://www.upnp.org/schemas/ehs/stg-v1.xsd");

      serializer.startTag(nns, XMLDATARECORD);
      for (Map.Entry<String, String> entry : fieldValues.entrySet()) {

        serializer.startTag(nns, XMLFIELD);

        serializer.attribute(nns, XMLNAME, entry.getKey());
        if (entry.getValue() != null) serializer.text(entry.getValue());
        else serializer.text("");

        serializer.endTag(nns, XMLFIELD);
      }
      serializer.endTag(nns, XMLDATARECORD);
      serializer.endTag(ns, XMLDATARECORDS);
      serializer.endDocument();
      return writer.toString();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Beispiel #9
0
  @Override
  public void serialize(XmlSerializer serializer) throws RuntimeException, IOException {
    serializer.setPrefix(XMLSettings.XMLSHORTNS, XMLSettings.XMLNS);
    serializer.startTag(XMLSettings.XMLNS, XMLTAG);

    serializer.startTag(XMLSettings.XMLNS, XMLNAME).text(name).endTag(XMLSettings.XMLNS, XMLNAME);
    serializer
        .startTag(XMLSettings.XMLNS, XMLDESCRIPTION)
        .text(description)
        .endTag(XMLSettings.XMLNS, XMLDESCRIPTION);
    //		serializer.startTag(XMLSettings.XMLNS, XMLPATH).text(path).endTag(XMLSettings.XMLNS,
    // XMLPATH);

    serializer.startTag(XMLSettings.XMLNS, XMLSITES);

    serializer.endTag(XMLSettings.XMLNS, XMLSITES);

    serializer.endTag(XMLSettings.XMLNS, XMLTAG);
  }
  public static synchronized String createXMLParameterValueList(
      HashMap<String, String> parameterValues) {
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();
    try {
      serializer.setOutput(writer);
      serializer.startDocument("UTF-8", false);

      String ns = null;
      serializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
      serializer.startTag(ns, XMLPARAMETERVALUELIST);
      serializer.attribute(
          "http://www.w3.org/2001/XMLSchema-instance",
          "schemaLocation",
          "urn:schemas-upnp-org:ehs:stg http://www.upnp.org/schemas/ehs/stg-v1.xsd");

      for (Map.Entry<String, String> entry : parameterValues.entrySet()) {
        serializer.startTag(ns, XMLPARAMETER);
        serializer.startTag(ns, XMLPARAMETERPATH);
        serializer.text(entry.getKey());
        serializer.endTag(ns, XMLPARAMETERPATH);

        serializer.startTag(ns, XMLPARAMETERVALUE);
        if (entry.getValue() != null) serializer.text(entry.getValue());
        else serializer.text("");
        serializer.endTag(ns, XMLPARAMETERVALUE);

        serializer.endTag(ns, XMLPARAMETER);
      }
      serializer.endTag(ns, XMLPARAMETERVALUELIST);
      serializer.endDocument();
      return writer.toString();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
 protected void declareExtraEntryNamespaces(XmlSerializer paramXmlSerializer) throws IOException {
   paramXmlSerializer.setPrefix("gsync", "http://schemas.google.com/gsync/data");
 }