本文整理汇总了Java中org.kxml2.io.KXmlParser.setFeature方法的典型用法代码示例。如果您正苦于以下问题:Java KXmlParser.setFeature方法的具体用法?Java KXmlParser.setFeature怎么用?Java KXmlParser.setFeature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.io.KXmlParser
的用法示例。
在下文中一共展示了KXmlParser.setFeature方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXMLResponse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public static Document getXMLResponse (Reader reader) {
Document doc = new Document();
try{
KXmlParser parser = new KXmlParser();
parser.setInput(reader);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
doc.parse(parser);
} catch (Exception e) {
System.err.println("couldn't process response payload from server!!");
doc = null;
}
try {
doc.getRootElement();
} catch (RuntimeException re) {
doc = null; //work around kxml bug where it should have failed to parse xml (doc == null)
//but instead returned an empty doc that throws an exception when you try to
//get its root element
}
return doc;
}
示例2: hasLayoutParams
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
@VisibleForTesting
static boolean hasLayoutParams(@NonNull Reader reader)
throws XmlPullParserException, IOException {
KXmlParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(reader);
while (true) {
int event = parser.next();
if (event == XmlPullParser.START_TAG) {
for (int i = 0; i < parser.getAttributeCount(); i++) {
if (parser.getAttributeName(i).startsWith(ATTR_LAYOUT_RESOURCE_PREFIX)) {
String prefix = parser.getAttributePrefix(i);
if (prefix != null && !prefix.isEmpty() &&
ANDROID_URI.equals(parser.getNamespace(prefix))) {
return true;
}
}
}
return false;
} else if (event == XmlPullParser.END_DOCUMENT) {
return false;
}
}
}
示例3: newPullParser
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
/**
* Returns a new pull parser with namespace support.
*/
public static XmlPullParser newPullParser() {
try {
KXmlParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
return parser;
} catch (XmlPullParserException e) {
throw new AssertionError();
}
}
示例4: newPullParser
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
/**
* Returns a new pull parser with namespace support.
*/
private static XmlPullParser newPullParser() {
try {
KXmlParser parser = new KXmlParser();
// parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
return parser;
} catch (XmlPullParserException e) {
throw new AssertionError(e);
}
}
示例5: getDocumentFromStream
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public static Document getDocumentFromStream(InputStream is) {
KXmlParser parser = new KXmlParser();
Document document = new Document();
try {
InputStreamReader reader = new InputStreamReader(is, "UTF-8");
parser.setInput(reader);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
document.parse(parser);
return document;
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
示例6: parse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public static XmlNode parse(Reader reader, boolean ignoreWhitespaces) throws Exception {
KXmlParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(reader);
parser.next();
XmlNode node = _parse(parser, ignoreWhitespaces);
return node;
}
示例7: createReferenceParser
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
private static KXmlParser createReferenceParser(PsiFile file) throws XmlPullParserException {
KXmlParser referenceParser = new KXmlParser();
referenceParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
referenceParser.setInput(new StringReader(file.getText()));
return referenceParser;
}
示例8: parse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
@Override
public Document parse(InputSource source) throws SAXException, IOException {
if (source == null) {
throw new IllegalArgumentException("source == null");
}
String namespaceURI = null;
String qualifiedName = null;
DocumentType doctype = null;
String inputEncoding = source.getEncoding();
String systemId = source.getSystemId();
DocumentImpl document = new DocumentImpl(
dom, namespaceURI, qualifiedName, doctype, inputEncoding);
document.setDocumentURI(systemId);
KXmlParser parser = new KXmlParser();
try {
parser.keepNamespaceAttributes();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);
if (source.getByteStream() != null) {
parser.setInput(source.getByteStream(), inputEncoding);
} else if (source.getCharacterStream() != null) {
parser.setInput(source.getCharacterStream());
} else if (systemId != null) {
URL url = new URL(systemId);
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
// TODO: if null, extract the inputEncoding from the Content-Type header?
parser.setInput(urlConnection.getInputStream(), inputEncoding);
} else {
throw new SAXParseException("InputSource needs a stream, reader or URI", null);
}
if (parser.nextToken() == XmlPullParser.END_DOCUMENT) {
throw new SAXParseException("Unexpected end of document", null);
}
parse(parser, document, document, XmlPullParser.END_DOCUMENT);
parser.require(XmlPullParser.END_DOCUMENT, null, null);
} catch (XmlPullParserException ex) {
if (ex.getDetail() instanceof IOException) {
throw (IOException) ex.getDetail();
}
if (ex.getDetail() instanceof RuntimeException) {
throw (RuntimeException) ex.getDetail();
}
LocatorImpl locator = new LocatorImpl();
locator.setPublicId(source.getPublicId());
locator.setSystemId(systemId);
locator.setLineNumber(ex.getLineNumber());
locator.setColumnNumber(ex.getColumnNumber());
SAXParseException newEx = new SAXParseException(ex.getMessage(), locator);
if (errorHandler != null) {
errorHandler.error(newEx);
}
throw newEx;
} finally {
IoUtils.closeQuietly(parser);
}
return document;
}
示例9: parse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
@Override
public Document parse(InputSource source) throws SAXException, IOException {
if (source == null) {
throw new IllegalArgumentException();
}
String namespaceURI = null;
String qualifiedName = null;
DocumentType doctype = null;
String inputEncoding = source.getEncoding();
String systemId = source.getSystemId();
DocumentImpl document = new DocumentImpl(
dom, namespaceURI, qualifiedName, doctype, inputEncoding);
document.setDocumentURI(systemId);
try {
KXmlParser parser = new KXmlParser();
parser.keepNamespaceAttributes();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);
if (source.getByteStream() != null) {
parser.setInput(source.getByteStream(), inputEncoding);
} else if (source.getCharacterStream() != null) {
parser.setInput(source.getCharacterStream());
} else if (systemId != null) {
URL url = new URL(systemId);
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
// TODO: if null, extract the inputEncoding from the Content-Type header?
parser.setInput(urlConnection.getInputStream(), inputEncoding);
} else {
throw new SAXParseException(
"InputSource needs a stream, reader or URI", null);
}
if(parser.nextToken() == XmlPullParser.END_DOCUMENT) {
throw new SAXParseException(
"Unexpected end of document", null);
}
parse(parser, document, document, XmlPullParser.END_DOCUMENT);
parser.require(XmlPullParser.END_DOCUMENT, null, null);
} catch (XmlPullParserException ex) {
if(ex.getDetail() instanceof IOException) {
throw (IOException)ex.getDetail();
}
if(ex.getDetail() instanceof RuntimeException) {
throw (RuntimeException)ex.getDetail();
}
LocatorImpl locator = new LocatorImpl();
locator.setPublicId(source.getPublicId());
locator.setSystemId(systemId);
locator.setLineNumber(ex.getLineNumber());
locator.setColumnNumber(ex.getColumnNumber());
SAXParseException newEx = new SAXParseException(ex.getMessage(),
locator);
if (errorHandler != null) {
errorHandler.error(newEx);
}
throw newEx;
}
return document;
}