本文整理汇总了Java中org.kxml2.io.KXmlParser.setInput方法的典型用法代码示例。如果您正苦于以下问题:Java KXmlParser.setInput方法的具体用法?Java KXmlParser.setInput怎么用?Java KXmlParser.setInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.io.KXmlParser
的用法示例。
在下文中一共展示了KXmlParser.setInput方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public static void main(String[] args) {
String xmlStr = "<start>"
+ "<ThisIsALongTagName/>"
+ "<ThisIsALongTagName/>"
+ "<ThisIsALongTagName/>"
+ "<ThisIsALongTagName/>"
+ "<ThisIsALongTagName/>"
+ "<ThisIsALongTagName/>"
+ "</start>";
System.out.println("xmlStr length: " + xmlStr.length());
ByteArrayInputStream bais = new ByteArrayInputStream(xmlStr.getBytes());
InputStreamReader isr = new InputStreamReader(bais);
try {
KXmlParser parser = new KXmlParser();
parser.setInput(isr);
while (parser.next() != XmlPullParser.END_DOCUMENT) {
if (parser.getEventType() == XmlPullParser.START_TAG) {
System.out.println("start tag: " + parser.getName());
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例3: 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;
}
}
}
示例4: parse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
private List<PinConfig> parse(InputStream configFileStream) throws XmlPullParserException, IOException{
List<PinConfig> pins = null;
KXmlParser parser = new KXmlParser();
// We set to null the encoding type. The parser should then dected it from the file stream.
parser.setInput(configFileStream, null);
int eventType = parser.getEventType();
while( eventType != XmlPullParser.END_DOCUMENT) {
if( eventType == XmlPullParser.START_TAG){
if( parser.getName().equals( PinsElement)) {
// We move to the next element inside the Wires element
parser.next();
pins = parsePinsElement(parser);
break;
}
}
eventType = parser.next();
}
return pins;
}
示例5: parse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
private List<SensorData> parse(InputStream configFileStream) throws XmlPullParserException, IOException{
List<SensorData> sensorNodes = null;
KXmlParser parser = new KXmlParser();
// We set to null the encoding type. The parser should then dected it from the file stream.
parser.setInput(configFileStream, null);
int eventType = parser.getEventType();
while( eventType != XmlPullParser.END_DOCUMENT) {
if( eventType == XmlPullParser.START_TAG){
if( parser.getName().equals( ContentDatasElement)) {
// We move to the next element inside the Wires element
parser.next();
sensorNodes = parseMeasurementsElement(parser);
break;
}
}
eventType = parser.next();
}
return sensorNodes;
}
示例6: parse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public void parse(InputStream configFileStream) throws IOException {
KXmlParser parser = new KXmlParser();
try {
// We set to null the encoding type. The parser should then dected it from the file stream.
parser.setInput(configFileStream, null);
int eventType = parser.getEventType();
while( eventType != XmlPullParser.END_DOCUMENT) {
if( eventType == XmlPullParser.START_TAG){
if( parser.getName().equals( ModbusDeviceElement)) {
// We move to the next element inside the Wires element
parser.next();
parseModbusDeviceElement(parser);
break;
}
}
eventType = parser.next();
}
} catch (XmlPullParserException e) {
Activator.log(LogService.LOG_INFO, "ModbusDeviceConfig reader, problem while reading the configuration: " + e.toString());
}
}
示例7: parse
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public void parse(InputStream configFileStream) throws IOException {
KXmlParser parser = new KXmlParser();
try {
// We set to null the encoding type. The parser should then dected it from the file stream.
parser.setInput(configFileStream, null);
int eventType = parser.getEventType();
while( eventType != XmlPullParser.END_DOCUMENT) {
if( eventType == XmlPullParser.START_TAG){
if( parser.getName().equals( WireAdminElement)) {
// We move to the next element inside the Wires element
parser.next();
parseWires(parser);
}
}
eventType = parser.next();
}
} catch (XmlPullParserException e) {
Activator.log(LogService.LOG_INFO, "WireConfig reader, problem while reading the configuration: " + e.toString());
}
}
示例8: 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());
}
}
示例9: loadDocument
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public void loadDocument(InputStream form)
throws IOException, XmlPullParserException
{
try {
setBusy(true);
long time = System.currentTimeMillis();
System.out.println("formview.enter()"+time);
KXmlParser parser = new KXmlParser();
parser.setInput(form, "UTF-8");
Container root = new Container(false);
this.deleteAll();
this.append(root);
m_controller = new PolishController(root, m_display, this);
setItemStateListener(m_controller);
super.setCommandListener(this);
//#debug info
System.out.println("Parsing form..");
m_doc.setRendererFactory(m_controller.getWidgetFactory());
// doc.registerDataSource(new SimulatedDataSource()); // for demo purposes
// doc.registerDataSource(new GPSDataSource(MainView._gpsDevice,this,true)); // for demo purposes
m_doc.setUserInterface(this);
//doc.setStoreProvider(this);
//doc.registerEventProvider("gps", this);
m_doc.addSubmitter(new HTTPSubmitter());
m_doc.addSerializer(new XFormsXMLSerializer());
m_doc.addSerializer(new MultipartRelatedSerializer());
m_doc.addSerializer(new MultipartFormDataSerializer());
//doc.addSubmitter(this);
m_doc.parse(parser);
//#debug info
System.out.println("Form construct took: "+(System.currentTimeMillis()-time)+"ms");
} catch(IOException ex1) {
throw ex1;
} finally {
setBusy(false);
}
}
示例10: addData
import org.kxml2.io.KXmlParser; //导入方法依赖的package包/类
public void addData(InputStream data, String dataId)
throws IOException, XmlPullParserException
{
KXmlParser parser = new KXmlParser();
parser.setInput(data, "UTF-8");
Document dataDoc = new Document();
dataDoc.parse(parser);
addData(dataDoc, dataId);
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}