本文整理汇总了Java中org.kxml2.io.KXmlParser类的典型用法代码示例。如果您正苦于以下问题:Java KXmlParser类的具体用法?Java KXmlParser怎么用?Java KXmlParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KXmlParser类属于org.kxml2.io包,在下文中一共展示了KXmlParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: parseElement
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
private String parseElement(KXmlParser parser) throws XmlPullParserException, IOException {
int eventType = parser.getEventType();
String element = null;
eventType = parser.next();
while( eventType != XmlPullParser.END_TAG) {
if( eventType == XmlPullParser.TEXT) {
element = parser.getText();
if(element.trim().length() == 0) element = null;
} else if( eventType == XmlPullParser.START_TAG) {
// We skip this subtree
parser.skipSubTree();
// SkipSubTree position us on the corresponding end tag
}
eventType = parser.next();
}
return element;
}
示例5: buildUserParser
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
private TransactionParser buildUserParser(KXmlParser parser) {
return new UserXmlParser(parser) {
@Override
protected void commit(User parsed) throws IOException, InvalidStructureException {
if (!parsed.getUserType().equals(User.TYPE_DEMO)) {
throw new InvalidStructureException(
"Demo user restore file must be for a user with user_type set to demo");
}
if ("".equals(parsed.getUsername()) || parsed.getUsername() == null) {
throw new InvalidStructureException(
"Demo user restore file must specify a username in the Registration block");
} else {
OfflineUserRestore.this.username = parsed.getUsername();
}
}
@Override
public User retrieve(String entityId) {
return null;
}
};
}
示例6: SavotSAXParser
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
/**
* Constructor
*
* @param consumer
* SavotSAXConsumer
* @param url
* url to parse
* @param enc
* encoding (example : UTF-8)
* @param debug
* boolean
*/
public SavotSAXParser(SavotSAXConsumer consumer, URL url, String enc,
boolean debug) {
try {
// new parser
KXmlParser parser = new KXmlParser();
engine = new SavotSAXEngine(consumer, parser, url, enc, debug);
// parse the stream
// engine.parse(parser);
// } catch (IOException e){
// System.err.println("SavotSAXParser : " + e);
} catch (Exception f) {
System.err.println("SavotSAXParser : " + f);
}
}
示例7: 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;
}
示例8: skipBlock
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
public void skipBlock(String tag) throws XmlPullParserException, IOException {
while(parser.getEventType() != KXmlParser.END_DOCUMENT) {
int eventType;
eventType = parser.next();
if(eventType == KXmlParser.START_DOCUMENT) {
} else if(eventType == KXmlParser.END_DOCUMENT) {
return;
} else if(eventType == KXmlParser.START_TAG) {
} else if(eventType == KXmlParser.END_TAG) {
if(parser.getName().equals(tag)) {
return;
}
} else if(eventType == KXmlParser.TEXT) {
}
}
}
示例9: process
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
public static void process(final UserSandbox sandbox, InputStream stream)
throws InvalidStructureException, IOException, XmlPullParserException,
UnfullfilledRequirementsException {
process(stream, new TransactionParserFactory() {
@Override
public TransactionParser getParser(KXmlParser parser) {
if (LedgerXmlParsers.STOCK_XML_NAMESPACE.equals(parser.getNamespace())) {
return new LedgerXmlParsers(parser, sandbox.getLedgerStorage());
} else if ("case".equalsIgnoreCase(parser.getName())) {
return new CaseXmlParser(parser, sandbox.getCaseStorage());
}
return null;
}
});
}
示例10: parseMeasurementsElement
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
private List<SensorData> parseMeasurementsElement(KXmlParser parser) throws XmlPullParserException, IOException {
List<SensorData> sensorDatas = new ArrayList<SensorData>();
int eventType = parser.getEventType();
while( eventType != XmlPullParser.END_TAG) {
if(eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals(ContentDataElement)) {
sensorDatas.add(this.parseMeasurementElement(parser));
}
}
eventType = parser.next();
}
return sensorDatas;
}
示例11: start
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
protected void start() {
// Get the Service XML from the device
try {
URL url = new URL(m_scpdUrl);
XmlPullParser p = new KXmlParser();
p.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
p.setInput(url.openConnection().getInputStream(), null);
while (p.getEventType() != XmlPullParser.END_DOCUMENT) {
if (p.getEventType() == XmlPullParser.START_TAG && p.getName().equalsIgnoreCase("actionList")) {
parseActionList(p);
} else if (p.getEventType() == XmlPullParser.START_TAG && p.getName().equalsIgnoreCase("serviceStateTable")) {
parseStateVariables(p);
}
p.next();
}
m_eventHandler.registerService(this);
} catch (FileNotFoundException e1) {
log.error("Given url not found (Error 404): " + m_scpdUrl);
} catch (Exception ee) {
ee.printStackTrace();
}
}
示例12: parsePinsElement
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
private List<PinConfig> parsePinsElement(KXmlParser parser) throws XmlPullParserException, IOException {
List<PinConfig> pins = new ArrayList<PinConfig>();
int eventType = parser.getEventType();
while( eventType != XmlPullParser.END_TAG) {
if(eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals(PinElement)) {
pins.add(this.parsePinElement(parser));
}
}
eventType = parser.next();
}
return pins;
}
示例13: parse
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
public Hashtable<String, String> parse() throws InvalidStructureException, IOException, XmlPullParserException, UnfullfilledRequirementsException {
String name = parser.getName();
Hashtable<String, String> ret = new Hashtable<String, String>();
boolean expecting = false;
String expected = null;
while (this.nextTagInBlock(name)) {
if (expecting) {
if (parser.getEventType() == KXmlParser.TEXT) {
ret.put(expected, parser.getText());
}
expecting = false;
}
if (matches()) {
expecting = true;
expected = parser.getName();
}
}
commit(ret);
return ret;
}
示例14: parseStatesElement
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
private void parseStatesElement(KXmlParser parser) throws XmlPullParserException, IOException {
int eventType = parser.next();
while( eventType != XmlPullParser.END_TAG) {
if(eventType == XmlPullParser.START_TAG) {
if(parser.getName().equals( StateElement)) {
ModbusState mdbSt= parseStateElement(parser);
if( mdbSt != null) {
states.add(mdbSt);
}
}
}
eventType = parser.next();
}
}
示例15: parseWires
import org.kxml2.io.KXmlParser; //导入依赖的package包/类
private void parseWires( KXmlParser parser) throws XmlPullParserException, IOException{
int eventType = parser.getEventType();
while( eventType != XmlPullParser.END_TAG) {
if(eventType == XmlPullParser.START_TAG) {
if(parser.getName().equals( WireElement)) {
// We move to the next elemeent inside the Wire elemente
parser.next();
parseWire(parser);
}
}
eventType = parser.next();
}
}