大家好,又见面了,我是你们的朋友全栈君。
本文整理匯總了Java中org.dom4j.io.SAXReader.read方法的典型用法代碼示例。如果您正苦於以下問題:Java SAXReader.read方法的具體用法?Java SAXReader.read怎麽用?Java SAXReader.read使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.io.SAXReader的用法示例。
在下文中一共展示了SAXReader.read方法的17個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: testdeployDefinition
點讚 4
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
@Test
public void testdeployDefinition() {
// 初始化
SAXReader reader = new SAXReader();
// 拿不到信息
URL url = this.getClass().getResource(“/process12.xml”);
Document document = null;
try {
document = reader.read(url);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String definitionContent = document.asXML();
// deploy first time
DefinitionHelper.getInstance().deployDefinition(“process”, “測試流程”, definitionContent, true);
}
開發者ID:alibaba,項目名稱:bulbasaur,代碼行數:20,
示例2: getFieldDefines
點讚 3
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private static Map getFieldDefines(File file, InputStream inputStream, Reader reader) {
SAXReader saxReader = new SAXReader();
Document document = null;
try {
if (file != null) {
document = saxReader.read(file);
} else if (inputStream != null) {
document = saxReader.read(inputStream);
} else if (reader != null) {
document = saxReader.read(reader);
} else {
throw new IllegalArgumentException(“all arguments is null”);
}
} catch (DocumentException e) {
throw new IllegalArgumentException(e);
}
return parseRootElements(document.getRootElement());
}
開發者ID:brucezee,項目名稱:jspider,代碼行數:19,
示例3: getValidDrcPathways
點讚 3
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
* Return a HasMap of valid DRC pathways from the pathways.xsd schema. Both the keys and values cantain the
* exact Strings of the valid pathways.
*
* @return HashMap of valid DRC pathways.
*/
private HashMap getValidDrcPathways() {
if (annotationPathwaysSchemaUrl == null)
return null;
HashMap pathways = new HashMap();
try {
SAXReader reader = new SAXReader();
Document document = reader.read(new URL(annotationPathwaysSchemaUrl));
List nodes = document.selectNodes(“//xsd:simpleType[@name=’pathwayType’]/xsd:restriction/xsd:enumeration”);
for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
Node node = (Node) iter.next();
pathways.put(node.valueOf(“@value”), node.valueOf(“@value”));
}
} catch (Throwable e) {
prtlnErr(“Error getValidDrcPathways(): ” + e);
}
return pathways;
}
開發者ID:NCAR,項目名稱:joai-project,代碼行數:28,
示例4: generate
點讚 3
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
void generate(File findbugsFile, File messageFile, File output, String[] tags) throws IOException {
SAXReader reader = new SAXReader();
try {
Document message = reader.read(messageFile);
Document findbugs = reader.read(findbugsFile);
@SuppressWarnings(“unchecked”)
List bugPatterns = message.selectNodes(“/MessageCollection/BugPattern”);
@SuppressWarnings(“unchecked”)
List findbugsAbstract = findbugs.selectNodes(“/FindbugsPlugin/BugPattern”);
writePatterns(findbugsAbstract, bugPatterns, output, tags);
} catch (DocumentException e) {
throw new IllegalArgumentException(e);
}
}
開發者ID:KengoTODA,項目名稱:sonarqube-rule-xml-generator,代碼行數:17,
示例5: createReader
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
* @since 1.4
*/
@Override
public HierarchicalStreamReader createReader(final URL in) {
try {
final SAXReader reader = new SAXReader();
final Document document = reader.read(in);
return new Dom4JReader(document, getNameCoder());
} catch (final DocumentException e) {
throw new StreamException(e);
}
}
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,
示例6: readDocument
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private Document readDocument(String path, ActionLog actionLog) throws DocumentException{
SAXReader reader=new SAXReader();
Document logDocument=reader.read(path);
Element log=logDocument.getRootElement();
Element action=log.addElement(“action”);
action.addElement(“name”).addText(actionLog.getName());
action.addElement(“s-time”).addText(actionLog.getStartTime().toString());
action.addElement(“e-time”).addText(actionLog.getEndTime().toString());
action.addElement(“result”).addText(actionLog.getResult());
System.out.println(“Write “+log.getName());
System.out.println(path);
return logDocument;
}
開發者ID:Hang-Hu,項目名稱:SimpleController,代碼行數:14,
示例7: loadXML
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
* Load XML File, Read it into Document
* @param filename
* The Name of the file which will be analysis
*/
public Document loadXML(final String filename)
{
//Document document = null;
try
{
final SAXReader saxReader = new SAXReader();
document = saxReader.read(new File(filename));
}
catch (final Exception ex)
{
ex.printStackTrace();
}
return document;
}
開發者ID:ansleliu,項目名稱:GraphicsViewJambi,代碼行數:20,
示例8: getXML
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
* 從文件讀取XML,輸入文件名,返回XML文檔
*
* @param processName
* @param processVersion
* @return Document
* @since 2012-12-27 下午06:52:23
*/
public Document getXML(String processName, @SuppressWarnings(“UnusedParameters”) int processVersion) {
SAXReader reader = new SAXReader();
URL url = this.getClass().getResource(“/” + processName.replaceAll(“\\.”, “/”) + “.xml”);
Document document;
try {
document = reader.read(url);
} catch (Exception e) {
logger.error(“xml流程文件讀取失敗!模板名:” + processName);
throw new NullPointerException(“xml流程文件讀取失敗!模板名:” + processName + “\n” + e);
}
return document;
}
開發者ID:alibaba,項目名稱:bulbasaur,代碼行數:23,
示例9: doPost
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(“text/html;charset=UTF-8”);
request.setCharacterEncoding(“UTF-8”);
//獲取HTTP請求的輸入流
InputStream is = request.getInputStream();
//已HTTP請求輸入流建立一個BufferedReader對象
BufferedReader br = new BufferedReader(new InputStreamReader(is,”UTF-8″));
StringBuilder sb = new StringBuilder();
//讀取HTTP請求內容
String buffer = null;
while ((buffer = br.readLine()) != null) {
sb.append(buffer);
}
String content = sb.toString().substring(sb.toString().indexOf(“<?xml “), sb.toString().indexOf(“”)+8);
System.out.println(content);
// 創建xml解析對象
SAXReader reader = new SAXReader();
// 定義一個文檔
Document document = null;
//將字符串轉換為
try {
document = reader.read(new ByteArrayInputStream(content.getBytes(“GBK”)));
} catch (DocumentException e) {
e.printStackTrace();
}
//response.setStatus(302);//設置302狀態碼,等同於response.setStatus(302);
//response.sendRedirect(“http://192.168.1.106:8080/udid?UDID=2123”);
//response.setStatus(HttpServletResponse.SC_FOUND);
response.setHeader(“Location”, “http://192.168.1.106:8080/udid.jsp?UDID=2123”);
response.setStatus(301);
}
開發者ID:shaojiankui,項目名稱:iOS-UDID-Safari,代碼行數:39,
示例10: parseXml
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
protected Element parseXml(InputStream stream){
SAXReader reader=new SAXReader();
Document document;
try {
document = reader.read(stream);
Element root=document.getRootElement();
return root;
} catch (DocumentException e) {
throw new RuleException(e);
}
}
開發者ID:youseries,項目名稱:urule,代碼行數:12,
示例11: XMLFile
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
public XMLFile(String filename) throws DocumentException, MalformedURLException {
this.filename = filename;
File file = new File(filename);
SAXReader saxReader = new SAXReader();
this.document = saxReader.read(file);
}
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:8,
示例12: readXML
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private Element readXML(String path){
SAXReader reader=new SAXReader();
Document document= null;
try {
document = reader.read(path);
} catch (DocumentException e) {
e.printStackTrace();
}
Element root=document.getRootElement();
return root;
}
開發者ID:Hang-Hu,項目名稱:SimpleController,代碼行數:12,
示例13: of
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
public static XmlParser of(Reader reader) throws DocumentException {
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(reader);
return new XmlParser(doc);
}
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:7,
示例14: getConfig
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
* 獲取配置
*
* @param name
* @return
* @throws Exception
*/
public static HttpConfig getConfig(String name) throws Exception {
HttpConfig hc = CONFIG_MAP.get(name);
if (hc == null) {
SAXReader reader = new SAXReader();
File xml = new File(HTTP_CONFIG_FILE);
Document doc;
Element root;
if (xml.exists()) {
try (FileInputStream in = new FileInputStream(xml); Reader read = new InputStreamReader(in, “UTF-8”)) {
doc = reader.read(read);
root = doc.getRootElement();
List els = root.selectNodes(“/root/configs/config”);
for (Element el : els) {
String nameStr = el.attributeValue(“name”);
String encodeType = el.attributeValue(“encodeType”);
String charset = el.attributeValue(“charset”);
String requestType = el.attributeValue(“requestType”);
String sendXML = el.attributeValue(“sendXML”);
String packHead = el.attributeValue(“packHead”);
String lowercaseEncode = el.attributeValue(“lowercaseEncode”);
String url = el.elementTextTrim(“url”);
String header = el.elementTextTrim(“header”);
String parameter = el.elementTextTrim(“parameter”);
String encodeField = el.elementTextTrim(“encodeField”);
String encodeKey = el.elementTextTrim(“encodeKey”);
String contentType = el.elementTextTrim(“contentType”);
HttpConfig config = new HttpConfig(nameStr, url, charset, header, parameter, requestType, contentType);
config.setSendXML(Boolean.valueOf(sendXML));
config.setEncodeKey(encodeKey);
config.setEncodeType(encodeType);
config.setEncodeFieldName(encodeField);
config.setLowercaseEncode(Boolean.valueOf(lowercaseEncode));
config.setPackHead(Boolean.valueOf(packHead));
CONFIG_MAP.put(nameStr, config);
if (nameStr.equals(name)) {
hc = config;
}
}
}
}
}
return hc;
}
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:52,
示例15: readRecipe
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
protected void readRecipe(String xml) {
try {
SAXReader reader = new SAXReader();
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); // never forget this!
org.xml.sax.InputSource inStream = new org.xml.sax.InputSource();
inStream.setCharacterStream(new java.io.StringReader(xml));
Document doc = reader.read(inStream);
Element root = doc.getRootElement();
List nodes = root.elements();
for (int i = 0; i < nodes.size(); i++) {
Element element = (Element) nodes.get(i);
if (element.getName().equals(“recipe_id”)) {
this.setRecipeId(Integer.parseInt(element.getText()));
}
else if (element.getName().equals(“recipe_name”)) {
this.setName(element.getText());
}
else if (element.getName().equals(“recipe_url”)) {
this.setRecipeUrl(element.getText());
}
else if (element.getName().equals(“rating”)) {
if(!element.getText().contains(“NaN”)) {
this.setRating(Integer.parseInt(element.getText()));
}
else {
this.setRating(0);
}
}
else if (element.getName().equals(“serving_sizes”)) {
this.calories = Integer.parseInt(element.element(“serving”).element(“calories”).getText());
}
else if (element.getName().equals(“recipe_images”)) {
this.setImageUrl(element.element(“recipe_image”).getText());
}
else if (element.getName().equals(“preparation_time_min”)) {
this.setPreparationTime(Double.parseDouble(element.getText()));
}
else if (element.getName().equals(“cooking_time_min”)) {
this.setCookingTime(Double.parseDouble(element.getText()));
}
else if (element.getName().equals(“ingredients”)) {
List ings = element.elements();
int foodId = 0;
String foodName = “”;
for(int j=0;j
{
Element ingredient = (Element) ings.get(j);
foodId = Integer.parseInt(ingredient.element(“food_id”).getText());
foodName = ingredient.element(“food_name”).getText();
Ingredient ing = new Ingredient(foodId,foodName);
ingredients.add(ing);
}
}
else if (element.getName().equals(“directions”)) {
List dirs = element.elements();
for (int j = 0; j
Element direct = (Element) dirs.get(j).element(“direction_description”);
directions.add(direct.getText());
}
}
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e);
}
}
開發者ID:aysenurbilgin,項目名稱:cww_framework,代碼行數:74,
示例16: processLog
點讚 2
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
* Concrete processing.
*
* @throws IOException
*/
protected void processLog() throws IOException {
final List tempFiles = new LinkedList();
try {
// check if it’s a directory
if (!super.agent.pathIsFile(fullyQualifiedResultPath)) {
reportLogPathIsNotFile();
return;
}
// get log and make an archive copy
final String archiveFileName = archiveManager.makeNewLogFileNameOnly(); // just a file name, w/o path
final File archiveFile = archiveManager.fileNameToLogPath(archiveFileName);
agent.readFile(super.fullyQualifiedResultPath, archiveFile);
// check if any
if (!archiveFile.exists()) {
return;
}
// save log info in the db if necessary
// parse
if (log.isDebugEnabled()) {
log.debug(“parse “);
}
final SAXReader reader = new SAXReader();
final Document checkstyle = reader.read(archiveFile);
// get and save
if (log.isDebugEnabled()) {
log.debug(“get statistics “);
}
final int problemFileCount = XMLUtils.intValueOf(checkstyle, “count(/checkstyle/file[count(error) > 0])”);
final int fileCount = XMLUtils.intValueOf(checkstyle, “count(/checkstyle/file)”);
final int problemCount = XMLUtils.intValueOf(checkstyle, “count(/checkstyle/file/error)”);
cm.addStepStatistics(super.stepRunID, StepRunAttribute.ATTR_CHECKSTYLE_ERRORS, problemCount);
cm.addStepStatistics(super.stepRunID, StepRunAttribute.ATTR_CHECKSTYLE_FILES_WITH_PROBLEMS, problemFileCount);
cm.addStepStatistics(super.stepRunID, StepRunAttribute.ATTR_CHECKSTYLE_FILES, fileCount);
cm.addRunStatistics(buildRunID, BuildRunAttribute.ATTR_CHECKSTYLE_ERRORS, problemCount);
cm.addRunStatistics(buildRunID, BuildRunAttribute.ATTR_CHECKSTYLE_FILES_WITH_PROBLEMS, problemFileCount);
cm.addRunStatistics(buildRunID, BuildRunAttribute.ATTR_CHECKSTYLE_FILES, fileCount);
// save log info
final StepLog stepLog = new StepLog();
stepLog.setStepRunID(super.stepRunID);
stepLog.setDescription(super.logConfig.getDescription());
stepLog.setPath(resolvedResultPath);
stepLog.setArchiveFileName(archiveFileName);
stepLog.setType(StepLog.TYPE_CUSTOM);
stepLog.setPathType(StepLog.PATH_TYPE_CHECKSTYLE_XML); // path type is file
stepLog.setFound((byte) 1);
cm.save(stepLog);
} catch (Exception e) {
throw IoUtils.createIOException(StringUtils.toString(e), e);
} finally {
IoUtils.deleteFilesHard(tempFiles);
}
}
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:66,
示例17: getXmlDocument
點讚 1
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
/**
* Load XML into a dom4j Document. If error, return null. No validation is performed.
*
* @param url A URL to an XML document
* @return An XML Document containing the dom4j DOM, or null if unable to process
* the file.
* @exception DocumentException If dom4j error
* @exception MalformedURLException If error in the URL
*/
public static Document getXmlDocument(URL url)
throws DocumentException, MalformedURLException {
// No validation…
SAXReader reader = new SAXReader(false);
Document document = reader.read(url);
return document;
}
開發者ID:NCAR,項目名稱:joai-project,代碼行數:17,
注:本文中的org.dom4j.io.SAXReader.read方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/150599.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...