Java Code Examples for org.xmlpull.v1.XmlSerializer#startTag()

The following examples show how to use org.xmlpull.v1.XmlSerializer#startTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlUtils.java    From HtmlCompat with Apache License 2.0 6 votes vote down vote up
public static final void writeSetXml(Set val, String name, XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {
    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "set");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    for (Object v : val) {
        writeValueXml(v, null, out);
    }

    out.endTag(null, "set");
}
 
Example 2
Source File: XmlUtils.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
public static final void writeSetXml(Set val, String name, XmlSerializer out)
		throws XmlPullParserException, java.io.IOException {
	if (val == null) {
		out.startTag(null, "null");
		out.endTag(null, "null");
		return;
	}

	out.startTag(null, "set");
	if (name != null) {
		out.attribute(null, "name", name);
	}

	for (Object v : val) {
		writeValueXml(v, null, out);
	}

	out.endTag(null, "set");
}
 
Example 3
Source File: XmlUtils.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Flatten a Map into an XmlSerializer.  The map can later be read back
 * with readThisMapXml().
 *
 * @param val      The map to be flattened.
 * @param name     Name attribute to include with this list's tag, or null for
 *                 none.
 * @param out      XmlSerializer to write the map into.
 * @param callback Method to call when an Object type is not recognized.
 * @hide
 * @see #writeMapXml(Map, OutputStream)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static final void writeMapXml(Map val, String name, XmlSerializer out,
									 WriteMapCallback callback) throws XmlPullParserException, java.io.IOException {

	if (val == null) {
		out.startTag(null, "null");
		out.endTag(null, "null");
		return;
	}

	out.startTag(null, "map");
	if (name != null) {
		out.attribute(null, "name", name);
	}

	writeMapXml(val, out, callback);

	out.endTag(null, "map");
}
 
Example 4
Source File: XmlUtils.java    From cwac-netsecurity with Apache License 2.0 6 votes vote down vote up
/**
 * Flatten a String[] into an XmlSerializer.  The list can later be read back
 * with readThisStringArrayXml().
 *
 * @param val The String array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static final void writeStringArrayXml(String[] val, String name, XmlSerializer out)
        throws XmlPullParserException, IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "string-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    for (int i=0; i<N; i++) {
        out.startTag(null, "item");
        out.attribute(null, "value", val[i]);
        out.endTag(null, "item");
    }

    out.endTag(null, "string-array");
}
 
Example 5
Source File: XmlUtils.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Flatten a String[] into an XmlSerializer.  The list can later be read back
 * with readThisStringArrayXml().
 *
 * @param val  The long array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out  XmlSerializer to write the array into.
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static void writeStringArrayXml(String[] val, String name, XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "string-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    for (String s : val) {
        out.startTag(null, "item");
        out.attribute(null, "value", s);
        out.endTag(null, "item");
    }

    out.endTag(null, "string-array");
}
 
Example 6
Source File: XmlUtils.java    From cwac-netsecurity with Apache License 2.0 6 votes vote down vote up
/**
 * Flatten a boolean[] into an XmlSerializer.  The list can later be read back
 * with readThisBooleanArrayXml().
 *
 * @param val The boolean array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static final void writeBooleanArrayXml(boolean[] val, String name, XmlSerializer out)
        throws XmlPullParserException, IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "boolean-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    for (int i=0; i<N; i++) {
        out.startTag(null, "item");
        out.attribute(null, "value", Boolean.toString(val[i]));
        out.endTag(null, "item");
    }

    out.endTag(null, "boolean-array");
}
 
Example 7
Source File: OSMWay.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
void xml(XmlSerializer xmlSerializer, String omkOsmUser) throws IOException {
    for (OSMNode node : linkedNodes) {
        node.xml(xmlSerializer, omkOsmUser);
    }
    xmlSerializer.startTag(null, "way");
    setOsmElementXmlAttributes(xmlSerializer, omkOsmUser);
    // generate nds
    setWayXmlNds(xmlSerializer);
    // generate tags
    super.xml(xmlSerializer, omkOsmUser);
    xmlSerializer.endTag(null, "way");
    for (OSMRelation relation : linkedRelations) {
        relation.xml(xmlSerializer, omkOsmUser);
    }
}
 
Example 8
Source File: XmlUtils.java    From android-job with Apache License 2.0 6 votes vote down vote up
public static final void writeSetXml(Set val, String name, XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {
    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "set");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    for (Object v : val) {
        writeValueXml(v, null, out);
    }

    out.endTag(null, "set");
}
 
Example 9
Source File: XmlUtils.java    From WeexOne with MIT License 5 votes vote down vote up
/**
 * Flatten a byte[] into an XmlSerializer.  The list can later be read back
 * with readThisByteArrayXml().
 *
 * @param val The byte array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 */
public static final void writeByteArrayXml(byte[] val, String name,
                                           XmlSerializer out)
    throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "byte-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    StringBuilder sb = new StringBuilder(val.length*2);
    for (int i=0; i<N; i++) {
        int b = val[i];
        int h = b>>4;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
        h = b&0xff;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
Example 10
Source File: XmlMapsGDataSerializer.java    From mytracks with Apache License 2.0 5 votes vote down vote up
private static void serializeId(XmlSerializer serializer, String id)
    throws IOException {
  if (StringUtils.isEmpty(id)) {
    return;
  }
  serializer.startTag(null /* ns */, "id");
  serializer.text(id);
  serializer.endTag(null /* ns */, "id");
}
 
Example 11
Source File: ImportFromSMathStudio.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
private void parseResult(final Element input, final Element result, boolean inRightOfPrevious, final XmlSerializer serializer) throws Exception
{
    final String term = FormulaBase.BaseType.RESULT.toString().toLowerCase(Locale.ENGLISH);
    serializer.startTag(FormulaList.XML_NS, term);
    serializer.attribute(FormulaList.XML_NS, FormulaList.XML_PROP_INRIGHTOFPREVIOUS,
            Boolean.toString(inRightOfPrevious));
    final List<Element> inputElements = XmlUtils.getElements(input, SM_TAG_MATH_EXPRESSION);
    parseTerm("leftTerm", inputElements, serializer, false);
    if (XmlUtils.ensureAttribute(result, "action", "numeric"))
    {
        final List<Element> resultElements = XmlUtils.getElements(result, SM_TAG_MATH_EXPRESSION);
        parseResultTerm("rightTerm", resultElements, serializer);
    }
    serializer.endTag(FormulaList.XML_NS, term);
}
 
Example 12
Source File: XmlUtils.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Flatten a byte[] into an XmlSerializer.  The list can later be read back
 * with readThisByteArrayXml().
 *
 * @param val The byte array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 */
public static final void writeByteArrayXml(byte[] val, String name,
        XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "byte-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    StringBuilder sb = new StringBuilder(val.length*2);
    for (int i=0; i<N; i++) {
        int b = val[i];
        int h = b>>4;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
        h = b&0xff;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
Example 13
Source File: OSMRelation.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
void xml(XmlSerializer xmlSerializer, String omkOsmUser) throws IOException {
    xmlSerializer.startTag(null, "relation");
    if (isModified()) {
        xmlSerializer.attribute(null, "action", "modify");
    }
    setOsmElementXmlAttributes(xmlSerializer, omkOsmUser);
    // generate members
    setRelationXmlMembers(xmlSerializer);
    // generate tags
    super.xml(xmlSerializer, omkOsmUser);
    xmlSerializer.endTag(null, "relation");
}
 
Example 14
Source File: XmlUtils.java    From WeexOne with MIT License 5 votes vote down vote up
/**
 * Flatten an int[] into an XmlSerializer.  The list can later be read back
 * with readThisIntArrayXml().
 *
 * @param val The int array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static final void writeIntArrayXml(int[] val, String name,
                                          XmlSerializer out)
    throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "int-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    for (int i=0; i<N; i++) {
        out.startTag(null, "item");
        out.attribute(null, "value", Integer.toString(val[i]));
        out.endTag(null, "item");
    }

    out.endTag(null, "int-array");
}
 
Example 15
Source File: SliceProviderPermissions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public synchronized void writeTo(XmlSerializer out) throws IOException {
    final int N = mPkgs.size();
    for (int i = 0; i < N; i++) {
        out.startTag(NAMESPACE, TAG_PKG);
        out.text(mPkgs.valueAt(i).toString());
        out.endTag(NAMESPACE, TAG_PKG);
    }
}
 
Example 16
Source File: XmlMapsGDataSerializer.java    From mytracks with Apache License 2.0 5 votes vote down vote up
private static void serializeCategory(XmlSerializer serializer,
    String category, String categoryScheme) throws IOException {
  if (StringUtils.isEmpty(category) && StringUtils.isEmpty(categoryScheme)) {
    return;
  }
  serializer.startTag(null /* ns */, "category");
  if (!StringUtils.isEmpty(category)) {
    serializer.attribute(null /* ns */, "term", category);
  }
  if (!StringUtils.isEmpty(categoryScheme)) {
    serializer.attribute(null /* ns */, "scheme", categoryScheme);
  }
  serializer.endTag(null /* ns */, "category");
}
 
Example 17
Source File: PersistentDataStore.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void saveConfigurationToXml(XmlSerializer serializer,
        BrightnessConfiguration config) throws IOException {
    serializer.startTag(null, TAG_BRIGHTNESS_CURVE);
    if (config.getDescription() != null) {
        serializer.attribute(null, ATTR_DESCRIPTION, config.getDescription());
    }
    final Pair<float[], float[]> curve = config.getCurve();
    for (int i = 0; i < curve.first.length; i++) {
        serializer.startTag(null, TAG_BRIGHTNESS_POINT);
        serializer.attribute(null, ATTR_LUX, Float.toString(curve.first[i]));
        serializer.attribute(null, ATTR_NITS, Float.toString(curve.second[i]));
        serializer.endTag(null, TAG_BRIGHTNESS_POINT);
    }
    serializer.endTag(null, TAG_BRIGHTNESS_CURVE);
}
 
Example 18
Source File: KeyChainSnapshotSerializer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void writeApplicationKeys(
        XmlSerializer xmlSerializer, List<WrappedApplicationKey> wrappedApplicationKeys)
        throws IOException {
    xmlSerializer.startTag(NAMESPACE, TAG_APPLICATION_KEYS);
    for (WrappedApplicationKey key : wrappedApplicationKeys) {
        xmlSerializer.startTag(NAMESPACE, TAG_APPLICATION_KEY);
        writeApplicationKeyProperties(xmlSerializer, key);
        xmlSerializer.endTag(NAMESPACE, TAG_APPLICATION_KEY);
    }
    xmlSerializer.endTag(NAMESPACE, TAG_APPLICATION_KEYS);
}
 
Example 19
Source File: XmlUtils.java    From JobSchedulerCompat with Apache License 2.0 5 votes vote down vote up
/**
 * Flatten an int[] into an XmlSerializer.  The list can later be read back
 * with readThisIntArrayXml().
 *
 * @param val The int array to be flattened.
 * @param name Name attribute to include with this array's tag, or null for
 *             none.
 * @param out XmlSerializer to write the array into.
 *
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readThisIntArrayXml
 */
public static final void writeIntArrayXml(int[] val, String name,
        XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;
    }

    out.startTag(null, "int-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    for (int i=0; i<N; i++) {
        out.startTag(null, "item");
        out.attribute(null, "value", Integer.toString(val[i]));
        out.endTag(null, "item");
    }

    out.endTag(null, "int-array");
}
 
Example 20
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
/**
 * �����ť����Xml�ļ�
 * 
 * @param v
 */
public void create(View v) {
	String name = etName.getText().toString().trim();
	String num = etNum.getText().toString().trim();
	if (TextUtils.isEmpty(name) || TextUtils.isEmpty(num)) {
		Toast.makeText(this, "��������ѧ�Ų���Ϊ�գ�", MODE_PRIVATE).show();
		return;
	}
	// ����Xml�ļ�
	try {
		// 1. ��ʼ��Xml���л���
		XmlSerializer serializer = Xml.newSerializer();
		// 2. ����������
		FileOutputStream fos = this.openFileOutput("student.xml", 0);
		serializer.setOutput(fos, "utf-8");
		// 3. ����Xml�ļ�
		serializer.startDocument("utf-8", true);

		serializer.startTag(null, "stu");

		// ����
		serializer.startTag(null, "name");
		serializer.text(name);
		serializer.endTag(null, "name");

		// ѧ��
		serializer.startTag(null, "num");
		serializer.text(num);
		serializer.endTag(null, "num");

		// �Ա�
		String sex = "��";
		int id = rgSex.getCheckedRadioButtonId();
		switch (id) {
		case R.id.rb_boy:// ��
			sex = "��";
			break;
		case R.id.rb_girl:// Ů
			sex = "Ů";
			break;
		case R.id.rb_yao:// ��
			sex = "��";
			break;
		default:
			break;
		}
		serializer.startTag(null, "sex");
		serializer.text(sex);
		serializer.endTag(null, "sex");

		serializer.endTag(null, "stu");
		serializer.endDocument();
		fos.close();
		Toast.makeText(this, "����Xml�ļ�succ", 0).show();
	} catch (Exception e) {
		Toast.makeText(this, "����Xml�ļ�ʧ��", 0).show();
		e.printStackTrace();
	}

}