本文整理汇总了Java中android.content.res.AXmlResourceParser.next方法的典型用法代码示例。如果您正苦于以下问题:Java AXmlResourceParser.next方法的具体用法?Java AXmlResourceParser.next怎么用?Java AXmlResourceParser.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.res.AXmlResourceParser
的用法示例。
在下文中一共展示了AXmlResourceParser.next方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPackageName
import android.content.res.AXmlResourceParser; //导入方法依赖的package包/类
public static String getPackageName(String apkname) throws Exception {
ZipInputStream inStream = new ZipInputStream(new FileInputStream(apkname));
ZipEntry entry;
while (((entry = inStream.getNextEntry()) != null)) {
if (entry.getName().equals("AndroidManifest.xml")) {
AXmlResourceParser parser=new AXmlResourceParser();
parser.open(inStream);
while (true) {
int type=parser.next();
if (type==XmlPullParser.START_TAG) {
for (int i=0;i!=parser.getAttributeCount();++i) {
if (parser.getAttributeName(i).equals("package"))
return parser.getAttributeValue(i);
}
break;
}
}
break;
}
}
return "";
}
示例2: getManifestXMLFromAPK
import android.content.res.AXmlResourceParser; //导入方法依赖的package包/类
public static String getManifestXMLFromAPK(String apkPath) {
ZipFile file = null;
StringBuilder xmlSb = new StringBuilder(100);
try {
File apkFile = new File(apkPath);
file = new ZipFile(apkFile, ZipFile.OPEN_READ);
ZipEntry entry = file.getEntry(DEFAULT_XML);
AXmlResourceParser parser=new AXmlResourceParser();
parser.open(file.getInputStream(entry));
StringBuilder sb=new StringBuilder(10);
final String indentStep=" ";
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT) {
switch (type) {
case XmlPullParser.START_DOCUMENT:
{
log(xmlSb,"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
break;
}
case XmlPullParser.START_TAG:
{
log(false,xmlSb,"%s<%s%s",sb,
getNamespacePrefix(parser.getPrefix()),parser.getName());
sb.append(indentStep);
int namespaceCountBefore=parser.getNamespaceCount(parser.getDepth()-1);
int namespaceCount=parser.getNamespaceCount(parser.getDepth());
for (int i=namespaceCountBefore;i!=namespaceCount;++i) {
log(xmlSb,"%sxmlns:%s=\"%s\"",
i==namespaceCountBefore?" ":sb,
parser.getNamespacePrefix(i),
parser.getNamespaceUri(i));
}
for (int i=0,size=parser.getAttributeCount();i!=size;++i) {
log(false,xmlSb, "%s%s%s=\"%s\""," ",
getNamespacePrefix(parser.getAttributePrefix(i)),
parser.getAttributeName(i),
getAttributeValue(parser,i));
}
// log("%s>",sb);
log(xmlSb,">");
break;
}
case XmlPullParser.END_TAG:
{
sb.setLength(sb.length()-indentStep.length());
log(xmlSb,"%s</%s%s>",sb,
getNamespacePrefix(parser.getPrefix()),
parser.getName());
break;
}
case XmlPullParser.TEXT:
{
log(xmlSb,"%s%s",sb,parser.getText());
break;
}
}
}
parser.close();
}
catch (Exception e) {
e.printStackTrace();
}
return xmlSb.toString();
}
示例3: getManifestXMLFromAPK
import android.content.res.AXmlResourceParser; //导入方法依赖的package包/类
public static String getManifestXMLFromAPK(String apkPath) {
ZipFile file = null;
StringBuilder xmlSb = new StringBuilder(100);
try {
File apkFile = new File(apkPath);
file = new ZipFile(apkFile, ZipFile.OPEN_READ);
ZipEntry entry = file.getEntry(DEFAULT_XML);
AXmlResourceParser parser=new AXmlResourceParser();
parser.open(file.getInputStream(entry));
StringBuilder sb=new StringBuilder(10);
final String indentStep=" ";
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT) {
switch (type) {
case XmlPullParser.START_DOCUMENT:
{
log(xmlSb,"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
break;
}
case XmlPullParser.START_TAG:
{
log(false,xmlSb,"%s<%s%s",sb,
getNamespacePrefix(parser.getPrefix()),parser.getName());
sb.append(indentStep);
int namespaceCountBefore=parser.getNamespaceCount(parser.getDepth()-1);
int namespaceCount=parser.getNamespaceCount(parser.getDepth());
for (int i=namespaceCountBefore;i!=namespaceCount;++i) {
log(xmlSb,"%sxmlns:%s=\"%s\"",
i==namespaceCountBefore?" ":sb,
parser.getNamespacePrefix(i),
parser.getNamespaceUri(i));
}
for (int i=0,size=parser.getAttributeCount();i!=size;++i) {
log(false,xmlSb, "%s%s%s=\"%s\""," ",
getNamespacePrefix(parser.getAttributePrefix(i)),
parser.getAttributeName(i),
getAttributeValue(parser,i));
}
// log("%s>",sb);
log(xmlSb,">");
break;
}
case XmlPullParser.END_TAG:
{
sb.setLength(sb.length()-indentStep.length());
log(xmlSb,"%s</%s%s>",sb,
getNamespacePrefix(parser.getPrefix()),
parser.getName());
break;
}
case XmlPullParser.TEXT:
{
log(xmlSb,"%s%s",sb,parser.getText());
break;
}
}
}
parser.close();
}
catch (Exception e) {
e.printStackTrace();
}
// System.out.println(xmlSb.toString());
return xmlSb.toString();
}
示例4: createNodeTree
import android.content.res.AXmlResourceParser; //导入方法依赖的package包/类
public static AXmlNode createNodeTree(InputStream in) {
AXmlNode root = new AXmlNode("root", 0);
try {
Stack<AXmlNode> stack = new Stack<AXmlNode>();
stack.push(root);
AXmlResourceParser parser = new AXmlResourceParser();
parser.open(in);
while (true) {
int type = parser.next();
if (type == XmlPullParser.END_DOCUMENT)
break;
switch (type) {
case XmlPullParser.START_TAG: {
AXmlNode parent = stack.peek();
AXmlNode node =
new AXmlNode(parser.getName(), parser.getDepth());
int count = parser.getAttributeCount();
for (int i = 0; i < count; ++i) {
node.mAttributes.put(
parser.getAttributeName(i),
getAttributeValue(parser, i));
}
parent.mChildNodes.add(node);
stack.push(node);
break;
}
case XmlPullParser.END_TAG: {
stack.pop();
break;
}
}
}
} catch (Exception e) {
root = null;
e.printStackTrace();
}
return root;
}
示例5: AXMLToXML
import android.content.res.AXmlResourceParser; //导入方法依赖的package包/类
public static String AXMLToXML(byte[] axml) throws Exception {
AXmlResourceParser parser = new AXmlResourceParser();
ByteArrayInputStream bais = new ByteArrayInputStream(axml);
parser.open(bais);
StringBuilder indent = new StringBuilder(10);
StringBuilder output = new StringBuilder(axml.length * 2);
final String indentStep = " ";
while (true) {
int type = parser.next();
if (type == XmlPullParser.END_DOCUMENT) {
break;
}
switch (type) {
case XmlPullParser.START_DOCUMENT: {
output.append(String
.format("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
output.append("\n");
break;
}
case XmlPullParser.START_TAG: {
output.append(String.format("%s<%s%s", indent,
getNamespacePrefix(parser.getPrefix()),
parser.getName()));
output.append("\n");
indent.append(indentStep);
int namespaceCountBefore = parser.getNamespaceCount(parser
.getDepth() - 1);
int namespaceCount = parser
.getNamespaceCount(parser.getDepth());
for (int i = namespaceCountBefore; i != namespaceCount; ++i) {
output.append(String.format("%sxmlns:%s=\"%s\"", indent,
parser.getNamespacePrefix(i),
parser.getNamespaceUri(i)));
output.append("\n");
}
for (int i = 0; i != parser.getAttributeCount(); ++i) {
output.append(String.format("%s%s%s=\"%s\"", indent,
getNamespacePrefix(parser.getAttributePrefix(i)),
parser.getAttributeName(i),
getAttributeValue(parser, i)));
output.append("\n");
}
output.append(String.format("%s>", indent));
output.append("\n");
break;
}
case XmlPullParser.END_TAG: {
indent.setLength(indent.length() - indentStep.length());
output.append(String.format("%s</%s%s>", indent,
getNamespacePrefix(parser.getPrefix()),
parser.getName()));
output.append("\n");
break;
}
case XmlPullParser.TEXT: {
output.append(String.format("%s%s", indent, parser.getText()));
output.append("\n");
break;
}
}
}
return output.toString();
}
示例6: main
import android.content.res.AXmlResourceParser; //导入方法依赖的package包/类
public static void main(String[] arguments) {
if (arguments.length<1) {
log("Usage: AXMLPrinter <binary xml file>");
return;
}
try {
AXmlResourceParser parser=new AXmlResourceParser();
parser.open(new FileInputStream(arguments[0]));
StringBuilder indent=new StringBuilder(10);
final String indentStep=" ";
while (true) {
int type=parser.next();
if (type==XmlPullParser.END_DOCUMENT) {
break;
}
switch (type) {
case XmlPullParser.START_DOCUMENT:
{
log("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
break;
}
case XmlPullParser.START_TAG:
{
log("%s<%s%s",indent,
getNamespacePrefix(parser.getPrefix()),parser.getName());
indent.append(indentStep);
int namespaceCountBefore=parser.getNamespaceCount(parser.getDepth()-1);
int namespaceCount=parser.getNamespaceCount(parser.getDepth());
for (int i=namespaceCountBefore;i!=namespaceCount;++i) {
log("%sxmlns:%s=\"%s\"",
indent,
parser.getNamespacePrefix(i),
parser.getNamespaceUri(i));
}
for (int i=0;i!=parser.getAttributeCount();++i) {
log("%s%s%s=\"%s\"",indent,
getNamespacePrefix(parser.getAttributePrefix(i)),
parser.getAttributeName(i),
getAttributeValue(parser,i));
}
log("%s>",indent);
break;
}
case XmlPullParser.END_TAG:
{
indent.setLength(indent.length()-indentStep.length());
log("%s</%s%s>",indent,
getNamespacePrefix(parser.getPrefix()),
parser.getName());
break;
}
case XmlPullParser.TEXT:
{
log("%s%s",indent,parser.getText());
break;
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}