本文整理匯總了Java中org.dom4j.io.SAXReader類的典型用法代碼示例。如果您正苦於以下問題:Java SAXReader類的具體用法?Java SAXReader怎麽用?Java SAXReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SAXReader類屬於org.dom4j.io包,在下文中一共展示了SAXReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: query_timestamp
import org.dom4j.io.SAXReader; //導入依賴的package包/類
/**
* 用於防釣魚,調用接口query_timestamp來獲取時間戳的處理函數
* 注意:遠程解析XML出錯,與服務器是否支持SSL等配置有關
* @return 時間戳字符串
* @throws IOException
* @throws DocumentException
* @throws MalformedURLException
*/
public static String query_timestamp() throws MalformedURLException,
DocumentException, IOException {
//構造訪問query_timestamp接口的URL串
String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" +AlipayConfig.input_charset;
StringBuffer result = new StringBuffer();
SAXReader reader = new SAXReader();
Document doc = reader.read(new URL(strUrl).openStream());
List<Node> nodeList = doc.selectNodes("//alipay/*");
for (Node node : nodeList) {
// 截取部分不需要解析的信息
if (node.getName().equals("is_success") && node.getText().equals("T")) {
// 判斷是否有成功標示
List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
for (Node node1 : nodeList1) {
result.append(node1.getText());
}
}
}
return result.toString();
}
示例2: readSettingsFile
import org.dom4j.io.SAXReader; //導入依賴的package包/類
public static DOM4JSettingsNode readSettingsFile(ImportInteraction importInteraction, FileFilter fileFilter) {
File file = importInteraction.promptForFile(fileFilter);
if (file == null) {
return null;
}
if (!file.exists()) {
importInteraction.reportError("File does not exist: " + file.getAbsolutePath());
return null; //we should really sit in a loop until they cancel or give us a valid file.
}
try {
SAXReader reader = new SAXReader();
Document document = reader.read(file);
return new DOM4JSettingsNode(document.getRootElement());
} catch (Throwable t) {
LOGGER.error("Unable to read file: " + file.getAbsolutePath(), t);
importInteraction.reportError("Unable to read file: " + file.getAbsolutePath());
return null;
}
}
示例3: parseText
import org.dom4j.io.SAXReader; //導入依賴的package包/類
public static Document parseText(String text) throws DocumentException, SAXException {
SAXReader reader = new SAXReader(false);
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://apache.org/xml/features/validation/schema", false);
String encoding = getEncoding(text);
InputSource source = new InputSource(new StringReader(text));
source.setEncoding(encoding);
Document result = reader.read(source);
// if the XML parser doesn't provide a way to retrieve the encoding,
// specify it manually
if (result.getXMLEncoding() == null) {
result.setXMLEncoding(encoding);
}
return result;
}
示例4: query_timestamp
import org.dom4j.io.SAXReader; //導入依賴的package包/類
/**
* 用於防釣魚,調用接口query_timestamp來獲取時間戳的處理函數
* 注意:遠程解析XML出錯,與服務器是否支持SSL等配置有關
*
* @return 時間戳字符串
* @throws IOException
* @throws DocumentException
* @throws MalformedURLException
*/
public static String query_timestamp() throws MalformedURLException, DocumentException, IOException {
//構造訪問query_timestamp接口的URL串
String strUrl = PayManager.HTTPS_MAPI_ALIPAY_COM_GATEWAY_DO + "?" + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset;
StringBuffer result = new StringBuffer();
SAXReader reader = new SAXReader();
Document doc = reader.read(new URL(strUrl).openStream());
List<Node> nodeList = doc.selectNodes("//alipay/*");
for (Node node : nodeList) {
// 截取部分不需要解析的信息
if (node.getName().equals("is_success") && node.getText().equals("T")) {
// 判斷是否有成功標示
List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
for (Node node1 : nodeList1) {
result.append(node1.getText());
}
}
}
return result.toString();
}
示例5: XMLBeanFactory
import org.dom4j.io.SAXReader; //導入依賴的package包/類
public XMLBeanFactory(InputStream input) {
SAXReader reader = new SAXReader();
Document doc = null;
try {
doc = reader.read(input);
if (doc == null)
return;
} catch (DocumentException e) {
e.printStackTrace();
}
Element root = doc.getRootElement();
@SuppressWarnings("unchecked")
List<Element> beanElems = root.elements();
for (Element beanElem : beanElems) {
Bean bean = parseBeanElement(beanElem);
addBean(bean);
}
instancetiateSingletons();
}
示例6: convert
import org.dom4j.io.SAXReader; //導入依賴的package包/類
/**
* 屬性轉化
* @param xmlFile xml文件
*/
private void convert(File xmlFile){
SAXReader reader = new SAXReader();
try {
Document document = reader.read(xmlFile);
Element root = document.getRootElement();
root.element("id").setText(artifactId);
root.element("name").setText(getJarPrefixName());
root.element("description").setText(null == description ? "暫無描述" : description);
String javaArguments = "";
if (arguments != null) {
for (String argument : arguments) {
javaArguments = " " + argument;
}
}
root.element("arguments").setText("-jar " + getJarName() + javaArguments);
saveXML(document,xmlFile);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: readXML
import org.dom4j.io.SAXReader; //導入依賴的package包/類
public String readXML(int xmlId, String textItem, int textId){
String xmlText;
String xmlPath;
Element xmlRoot,secRoot;
URL xmlURL;
Document xmlFile;
SAXReader reader = new SAXReader();
xmlPath = "./data/language/" +
language +
"/" +
rEadC.getConfig(rEadC.userConfig , "text", "xml" + xmlId);
xmlURL = Resources.getResource(xmlPath);
try {
xmlFile = reader.read(xmlURL);
xmlRoot = xmlFile.getRootElement();
secRoot = xmlRoot.element(textItem);
xmlText = secRoot.elementText("adv" + textId);
return xmlText;
} catch (DocumentException e) {
e.printStackTrace();
}
return null;
}
示例8: parseXml
import org.dom4j.io.SAXReader; //導入依賴的package包/類
/**
* 解析微信發來的請求(XML)
*
* @param request
* @return Map<String, String>
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static Map<String, String> parseXml(HttpServletRequest request) throws Exception {
// 將解析結果存儲在HashMap中
Map<String, String> map = new HashMap<String, String>();
// 從request中取得輸入流
InputStream inputStream = request.getInputStream();
// 讀取輸入流
SAXReader reader = new SAXReader();
Document document = reader.read(inputStream);
// 得到xml根元素
Element root = document.getRootElement();
// 得到根元素的所有子節點
List<Element> elementList = root.elements();
// 遍曆所有子節點
for (Element e : elementList)
map.put(e.getName(), e.getText());
// 釋放資源
inputStream.close();
inputStream = null;
return map;
}
示例9: loadQueryCollection
import org.dom4j.io.SAXReader; //導入依賴的package包/類
public void loadQueryCollection(String location)
{
try
{
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
SAXReader reader = new SAXReader();
Document document = reader.read(is);
is.close();
QueryCollection collection = QueryCollectionImpl.createQueryCollection(document.getRootElement(), dictionaryService, namespaceService);
collections.put(location, collection);
}
catch (DocumentException de)
{
throw new AlfrescoRuntimeException("Error reading XML", de);
}
catch (IOException e)
{
throw new AlfrescoRuntimeException("IO Error reading XML", e);
}
}
示例10: hasRoot
import org.dom4j.io.SAXReader; //導入依賴的package包/類
public static boolean hasRoot(File file, String name)
{
SAXReader reader = new SAXReader();
try(InputStream in = new FileInputStream(file))
{
Document doc = reader.read(in);
Element rootEle = doc.getRootElement();
String rootEleName = rootEle.getName();
return rootEleName.equals(name);
}
catch (Exception e)
{}
return false;
}
示例11: query_timestamp
import org.dom4j.io.SAXReader; //導入依賴的package包/類
/**
* 用於防釣魚,調用接口query_timestamp來獲取時間戳的處理函數
* 注意:遠程解析XML出錯,與服務器是否支持SSL等配置有關
* @return 時間戳字符串
* @throws IOException
* @throws DocumentException
* @throws MalformedURLException
*/
public static String query_timestamp(AlipayConfig config) throws MalformedURLException,
DocumentException, IOException {
//構造訪問query_timestamp接口的URL串
String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + config.getPartnerId() + "&_input_charset" +AlipayConfig.inputCharset;
StringBuffer result = new StringBuffer();
SAXReader reader = new SAXReader();
Document doc = reader.read(new URL(strUrl).openStream());
List<Node> nodeList = doc.selectNodes("//alipay/*");
for (Node node : nodeList) {
// 截取部分不需要解析的信息
if (node.getName().equals("is_success") && node.getText().equals("T")) {
// 判斷是否有成功標示
List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
for (Node node1 : nodeList1) {
result.append(node1.getText());
}
}
}
return result.toString();
}
示例12: getCollectionDocumentFromWebService
import org.dom4j.io.SAXReader; //導入依賴的package包/類
private Document getCollectionDocumentFromWebService ( String _key )
{
Document collectionDocument = null;
// make the call to DDS and get ListCollections
try {
URLConnection connection = new URL ("http://www.dlese.org/dds/services/ddsws1-1?verb=Search&ky=" + _key + "&n=200&s=0" ).openConnection();
connection.setDoOutput( true );
connection.setDoInput(true);
((HttpURLConnection)connection).setRequestMethod("GET");
SAXReader xmlReader = new SAXReader();
collectionDocument = xmlReader.read(connection.getInputStream());
} catch ( Exception e ) {
e.printStackTrace();
}
return collectionDocument;
}
示例13: getValidMetadataFormats
import org.dom4j.io.SAXReader; //導入依賴的package包/類
/**
* Grabs the valid metadata formats from the DPC schema.
*
* @return A list of valid metadata formats.
*/
public ArrayList getValidMetadataFormats() {
String metadataFormatSchemaUrl =
getServlet().getServletContext().getInitParameter("metadataFormatSchemaUrl");
if (metadataFormatSchemaUrl == null)
return null;
if (validMetadataFormats == null) {
try {
validMetadataFormats = new ArrayList();
SAXReader reader = new SAXReader();
Document document = reader.read(new URL(metadataFormatSchemaUrl));
validMetadataFormats.add("-- SELECT FORMAT --");
List nodes = document.selectNodes("//xsd:simpleType[@name='itemFormatType']/xsd:restriction/xsd:enumeration");
for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
Node node = (Node) iter.next();
validMetadataFormats.add(node.valueOf("@value"));
}
} catch (Throwable e) {
prtlnErr("Error getValidMetadataFormats(): " + e);
validMetadataFormats = null;
}
}
return validMetadataFormats;
}
示例14: getConfig
import org.dom4j.io.SAXReader; //導入依賴的package包/類
@Override
public Element getConfig() {
final File boardFile = new File(getConfigFile());
if (boardFile.exists()) {
try {
return new SAXReader(false).read(boardFile).getRootElement();
} catch (DocumentException ex) {
QLog.l().logger()
.error("Невозможно прочитать файл конфигурации главного табло. " + ex
.getMessage());
return DocumentHelper.createElement("Ответ");
}
} else {
QLog.l().logger()
.warn("Файл конфигурации главного табло \"" + configFile + "\" не найден. ");
return DocumentHelper.createElement("Ответ");
}
}
示例15: getValidCollectionKeys
import org.dom4j.io.SAXReader; //導入依賴的package包/類
/**
* Grabs the collection keys from the DPC keys schema.
*
* @return A list of valid colleciton keys.
*/
public ArrayList getValidCollectionKeys() {
String collectionKeySchemaUrl =
getServlet().getServletContext().getInitParameter("collectionKeySchemaUrl");
if (collectionKeySchemaUrl == null)
return null;
if (validCollectionKeys == null) {
try {
validCollectionKeys = new ArrayList();
SAXReader reader = new SAXReader();
Document document = reader.read(new URL(collectionKeySchemaUrl));
validCollectionKeys.add("-- SELECT COLLECTION KEY --");
List nodes = document.selectNodes("//xsd:simpleType[@name='keyType']/xsd:restriction/xsd:enumeration");
for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
Node node = (Node) iter.next();
validCollectionKeys.add(node.valueOf("@value"));
}
} catch (Throwable e) {
prtlnErr("Error getCollectionKeys(): " + e);
validCollectionKeys = null;
}
}
return validCollectionKeys;
}