本文整理了Java中android.util.Xml
类的一些代码示例,展示了Xml
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Xml
类的具体详情如下:
包路径:android.util.Xml
类名称:Xml
暂无
代码示例来源:origin: facebook/stetho
private List<RssItem> parseRss(byte[] body) throws IOException, XmlPullParserException {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new ByteArrayInputStream(body), "UTF-8");
List<RssItem> items = new RssParser(parser).parse();
Log.d(TAG, "Fetched " + items.size() + " items");
return items;
}
代码示例来源: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: ZieIony/Carbon
/**
* Create a drawable from an XML document using an optional {@link Resources.Theme}. For more
* information on how to create resources in XML, see
* <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
*/
public static Drawable createFromXml(Resources r, XmlPullParser parser, Resources.Theme theme) throws XmlPullParserException, IOException {
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
Drawable drawable = createFromXmlInner(r, parser, attrs, theme);
if (drawable == null) {
throw new RuntimeException("Unknown initial tag: " + parser.getName());
}
return drawable;
}
代码示例来源:origin: Jiangzqts/EpubRead
public static boolean parseQuietly(ZLFile file, DefaultHandler handler) {
try {
Xml.parse(file.getInputStream(), Xml.Encoding.UTF_8, handler);
return true;
} catch (Exception e) {
return false;
}
}
}
代码示例来源:origin: adolfAn/FBReader_AS
public static boolean parseQuietly(ZLFile file, DefaultHandler handler) {
try {
Xml.parse(file.getInputStream(), Xml.Encoding.UTF_8, handler);
return true;
} catch (Exception e) {
return false;
}
}
}
代码示例来源:origin: evernote/android-job
/**
* Read an ArrayList from an InputStream containing XML. The stream can
* previously have been written by writeListXml().
*
* @param in The InputStream from which to read.
*
* @return ArrayList The resulting list.
*
* @see #readMapXml
* @see #readValueXml
* @see #readThisListXml
* @see #writeListXml
*/
public static final ArrayList readListXml(InputStream in)
throws XmlPullParserException, java.io.IOException {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, null);
return (ArrayList) readValueXml(parser, new String[1]);
}
代码示例来源: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: ZieIony/Carbon
/**
* Create a drawable from an XML document using an optional {@link Resources.Theme}. For more
* information on how to create resources in XML, see
* <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
*/
public Drawable createFromXml(XmlPullParser parser, Resources.Theme theme) throws XmlPullParserException, IOException {
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
Drawable drawable = createFromXmlInner(parser, attrs, theme);
if (drawable == null) {
throw new RuntimeException("Unknown initial tag: " + parser.getName());
}
return drawable;
}
代码示例来源:origin: ydcx/KooReader
public static boolean parseQuietly(ZLFile file, DefaultHandler handler) {
try {
Xml.parse(file.getInputStream(), Xml.Encoding.UTF_8, handler);
return true;
} catch (Exception e) {
return false;
}
}
}
代码示例来源:origin: evernote/android-job
/**
* Read a HashMap from an InputStream containing XML. The stream can
* previously have been written by writeMapXml().
*
* @param in The InputStream from which to read.
*
* @return HashMap The resulting map.
*
* @see #readListXml
* @see #readValueXml
* @see #readThisMapXml
* #see #writeMapXml
*/
@SuppressWarnings("unchecked")
public static final HashMap<String, ?> readMapXml(InputStream in)
throws XmlPullParserException, java.io.IOException {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, null);
return (HashMap<String, ?>) readValueXml(parser, new String[1]);
}
代码示例来源: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: mikepenz/Android-Iconics
/**
* Uses the styleable tags to get the iconics data of menu items. Useful for set icons into
* {@code BottomNavigationView}
* <p>
* By default, menus don't show icons for sub menus, but this can be enabled via reflection
* So use this function if you want that sub menu icons are checked as well
*/
public static void parseXmlAndSetIconicsDrawables(@NonNull Context context,
int menuId,
@NonNull Menu menu,
boolean checkSubMenus) {
try {
XmlResourceParser parser = context.getResources().getXml(menuId);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(context, attrs, parser, menu, checkSubMenus);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: Wilm0r/giggity
private void loadXml(BufferedReader in, ContentHandler parser) {
try {
Xml.parse(in, parser);
in.close();
} catch (Exception e) {
Log.e("Schedule.loadXml", "XML parse exception: " + e);
e.printStackTrace();
throw new LoadException("XML parsing problem: " + e);
}
}
代码示例来源:origin: evernote/android-job
/**
* Read a HashSet from an InputStream containing XML. The stream can
* previously have been written by writeSetXml().
*
* @param in The InputStream from which to read.
*
* @return HashSet The resulting set.
*
* @throws XmlPullParserException
* @throws java.io.IOException
*
* @see #readValueXml
* @see #readThisSetXml
* @see #writeSetXml
*/
public static final HashSet readSetXml(InputStream in)
throws XmlPullParserException, java.io.IOException {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, null);
return (HashSet) readValueXml(parser, new String[1]);
}
代码示例来源:origin: k9mail/k-9
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(os, "UTF-8");
代码示例来源:origin: android-hacker/VirtualXposed
private void generateServicesMap(List<ResolveInfo> services, Map<String, SyncAdapterInfo> map,
RegisteredServicesParser accountParser) {
for (ResolveInfo info : services) {
XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo, "android.content.SyncAdapter");
if (parser != null) {
try {
AttributeSet attributeSet = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Nothing to do
}
if ("sync-adapter".equals(parser.getName())) {
SyncAdapterType adapterType = parseSyncAdapterType(
accountParser.getResources(mContext, info.serviceInfo.applicationInfo), attributeSet);
if (adapterType != null) {
String key = adapterType.accountType + "/" + adapterType.authority;
map.put(key, new SyncAdapterInfo(adapterType, info.serviceInfo));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
代码示例来源:origin: billthefarmer/currency
public boolean startParser(String s)
{
// Create the map
map = new LinkedHashMap<>();
// Read the xml from the url
try
{
URL url = new URL(s);
InputStream stream = url.openStream();
Handler handler = new Handler();
Xml.parse(stream, Xml.Encoding.UTF_8, handler);
return true;
}
catch (Exception e)
{
map.clear();
}
return false;
}
代码示例来源:origin: androidannotations/androidannotations
public static Set<String> deserialize(String data) {
Set<String> stringSet = new TreeSet<>();
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(new StringReader(data));
parser.next();
parser.require(XmlPullParser.START_TAG, NAMESPACE, SET_TAG);
while (parser.next() != XmlPullParser.END_TAG) {
parser.require(XmlPullParser.START_TAG, NAMESPACE, STRING_TAG);
parser.next();
parser.require(XmlPullParser.TEXT, null, null);
stringSet.add(parser.getText());
parser.next();
parser.require(XmlPullParser.END_TAG, null, STRING_TAG);
}
} catch (XmlPullParserException e) {
Log.w("getStringSet", e);
return null;
} catch (IOException e) {
Log.w("getStringSet", e);
return null;
}
return stringSet;
}
}
代码示例来源:origin: google/ExoPlayer
throws XmlPullParserException, IOException {
scratchOutputStream.reset();
XmlSerializer xmlSerializer = Xml.newSerializer();
xmlSerializer.setOutput(scratchOutputStream, C.UTF8_NAME);
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainAttributes_shouldReturnValuesFromResources() throws Exception {
XmlPullParser parser = resources.getXml(R.xml.xml_attrs);
parser.next();
parser.next();
AttributeSet attributes = Xml.asAttributeSet(parser);
TypedArray typedArray = resources
.obtainAttributes(attributes, new int[]{android.R.attr.title, android.R.attr.scrollbarFadeDuration});
assertThat(typedArray.getString(0)).isEqualTo("Android Title");
assertThat(typedArray.getInt(1, 0)).isEqualTo(1111);
typedArray.recycle();
}
内容来源于网络,如有侵权,请联系作者删除!