本文整理匯總了Java中org.dom4j.io.SAXReader.read方法的典型用法代碼示例。如果您正苦於以下問題:Java SAXReader.read方法的具體用法?Java SAXReader.read怎麽用?Java SAXReader.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.io.SAXReader
的用法示例。
在下文中一共展示了SAXReader.read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testdeployDefinition
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);
}
示例2: getFieldDefines
import org.dom4j.io.SAXReader; //導入方法依賴的package包/類
private static Map<String, FieldDefine> 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());
}
示例3: getValidDrcPathways
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;
}
示例4: generate
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<Node> bugPatterns = message.selectNodes("/MessageCollection/BugPattern");
@SuppressWarnings("unchecked")
List<Node> findbugsAbstract = findbugs.selectNodes("/FindbugsPlugin/BugPattern");
writePatterns(findbugsAbstract, bugPatterns, output, tags);
} catch (DocumentException e) {
throw new IllegalArgumentException(e);
}
}
示例5: createReader
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);
}
}
示例6: readDocument
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;
}
示例7: loadXML
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;
}
示例8: getXML
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;
}
示例9: doPost
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("</plist>")+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);
}
示例10: parseXml
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);
}
}
示例11: XMLFile
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);
}
示例12: readXML
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;
}
示例13: of
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);
}
示例14: getConfig
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<Element> 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;
}
示例15: readRecipe
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<ings.size();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<Element> dirs = element.elements();
for (int j = 0; j<dirs.size(); j++) {
Element direct = (Element) dirs.get(j).element("direction_description");
directions.add(direct.getText());
}
}
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e);
}
}