📄 xmlfilterrefact.java
字号:
package com.hongsoft.agile.xmlParser;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLFilterImpl;
/**
* 该类参考其它部分代码进行了改造,参见www.jdom.org www.jdon.org
* 它在基本的SAX2的过虑器的实现上,添加了一些方便的方法
*/
public class XMLFilterRefact extends XMLFilterImpl
{
public XMLFilterRefact()
{
}
/**
* 用指定的parent来构造XML filter
*/
public XMLFilterRefact(XMLReader parent)
{
super(parent);
}
/**
* start the element
* @param uri 元素的名字空间URI
* @param localName local name
*/
public void startElement (String uri, String localName) throws SAXException
{
startElement(uri, localName, "", EMPTY_ATTS);
}
public void startElement (String localName) throws SAXException
{
startElement("", localName, "", EMPTY_ATTS);
}
/**
* end the element
* @param uri 元素的名字空间URI
* @param localName local name
*/
public void endElement (String uri, String localName) throws SAXException
{
endElement(uri, localName, "");
}
public void endElement (String localName) throws SAXException
{
endElement("", localName, "");
}
/**
* add the element
* @param uri 元素的名字空间URI
* @param localName local name
*/
public void emptyElement (String uri, String localName, String qName,
Attributes atts) throws SAXException
{
startElement(uri, localName, qName, atts);
endElement(uri, localName, qName);
}
public void emptyElement (String uri, String localName) throws SAXException
{
emptyElement(uri, localName, "", EMPTY_ATTS);
}
public void emptyElement (String localName) throws SAXException
{
emptyElement("", localName, "", EMPTY_ATTS);
}
/**
* 一次性的添加元素并设置属性
* @param uri 元素的名字空间URI
* @param localName local name
*/
public void dataElement (String uri, String localName, String qName,
Attributes atts, String content) throws SAXException
{
startElement(uri, localName, qName, atts);
characters(content);
endElement(uri, localName, qName);
}
public void dataElement (String uri, String localName, String content)
throws SAXException
{
dataElement(uri, localName, "", EMPTY_ATTS, content);
}
public void dataElement (String localName, String content)
throws SAXException
{
dataElement("", localName, "", EMPTY_ATTS, content);
}
/**
* 串与char的转换
* @param data
* @throws SAXException
*/
public void characters (String data) throws SAXException
{
char ch[] = data.toCharArray();
characters(ch, 0, ch.length);
}
////////////////////////////////////////////////////////////////////
// Constants.
////////////////////////////////////////////////////////////////////
protected static final Attributes EMPTY_ATTS = new AttributesImpl();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -