当前位置: 首页>>代码示例>>Java>>正文


Java KXmlParser.setInput方法代码示例

本文整理汇总了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;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:25,代码来源:CommUtil.java

示例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();
	}
}
 
开发者ID:stefanhaustein,项目名称:kxml2,代码行数:27,代码来源:LongStringTest.java

示例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;
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:LayoutInflationDetector.java

示例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;
}
 
开发者ID:lathil,项目名称:Ptoceti,代码行数:25,代码来源:ConfigReader.java

示例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;
}
 
开发者ID:lathil,项目名称:Ptoceti,代码行数:27,代码来源:SensorNodeConfig.java

示例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());
	}
}
 
开发者ID:lathil,项目名称:Ptoceti,代码行数:26,代码来源:ModbusDeviceConfig.java

示例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());
	}
}
 
开发者ID:lathil,项目名称:Ptoceti,代码行数:25,代码来源:WireConfig.java

示例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());
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:16,代码来源:XmlComparator.java

示例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);
    }
}
 
开发者ID:okoskimi,项目名称:Xfolite,代码行数:40,代码来源:XFormsForm.java

示例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);
}
 
开发者ID:okoskimi,项目名称:Xfolite,代码行数:10,代码来源:XFormsForm.java

示例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;
}
 
开发者ID:Ericsson-LMF,项目名称:IoT-Gateway,代码行数:10,代码来源:XmlParser.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:LayoutPsiPullParserTest.java

示例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;
}
 
开发者ID:thahn0720,项目名称:agui_framework,代码行数:70,代码来源:DocumentBuilderImpl.java

示例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;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:71,代码来源:DocumentBuilderImpl.java


注:本文中的org.kxml2.io.KXmlParser.setInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。