📄 e549. getting the attributes of an element during xml sax parsing.txt
字号:
// Create a handler for SAX events
DefaultHandler handler = new MyHandler();
// Parse an XML file using SAX;
// e517 The Quintessential Program to Parse an XML File Using SAX
parseXmlFile("infilename.xml", handler, true);
// This class listens for startElement SAX events
static class MyHandler extends DefaultHandler {
// This method is called when an element is encountered
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) {
// Get the number of attribute
int length = atts.getLength();
// Process each attribute
for (int i=0; i<length; i++) {
// Get names and values for each attribute
String name = atts.getQName(i);
String value = atts.getValue(i);
// The following methods are valid only if the parser is namespace-aware
// The uri of the attribute's namespace
String nsUri = atts.getURI(i);
// This is the name without the prefix
String lName = atts.getLocalName(i);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -