add readBySax

This commit is contained in:
Looly
2020-09-30 11:30:10 +08:00
parent f6a18afcba
commit 61c0633da7
3 changed files with 113 additions and 0 deletions

View File

@@ -9,10 +9,13 @@ import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.xpath.XPathConstants;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
/**
* {@link XmlUtil} 工具类
@@ -148,6 +151,18 @@ public class XmlUtilTest {
Assert.assertNotNull(doc);
}
@Test
public void readBySaxTest(){
final Set<String> eles = CollUtil.newHashSet(
"returnsms", "returnstatus", "message", "remainpoint", "taskID", "successCounts");
XmlUtil.readBySax(ResourceUtil.getStream("test.xml"), new DefaultHandler(){
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
Assert.assertTrue(eles.contains(localName));
}
});
}
@Test
public void mapToXmlTestWithOmitXmlDeclaration() {