use of org.dom4j.DocumentException in project EssayJoke by qiyei2015.
the class Dom4jHelper method parseXml.
/**
* 解析xml
* @param inputStream
*/
public static void parseXml(InputStream inputStream) {
try {
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(inputStream);
Element element = document.getRootElement();
readeNode(element, "");
} catch (DocumentException e) {
e.printStackTrace();
}
}
use of org.dom4j.DocumentException in project jbosstools-hibernate by jbosstools.
the class ResourceReadUtils method adjustXmlText.
/**
* Parse, i.e. adjust xml text so attributes for same xmls
* will be in one order.
*
* @param sample
* @return adjusted xml
*/
public static String adjustXmlText(String sample) {
Document doc = null;
try {
doc = DocumentHelper.parseText(sample);
} catch (DocumentException e) {
// ignore
}
if (doc == null) {
return sample;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ConfigurationXMLFactory.dump(baos, doc.getRootElement());
return baos.toString().trim();
}
use of org.dom4j.DocumentException in project core by craftercms.
the class AbstractFileBasedContentStoreAdapter method doFindItem.
@Override
protected Item doFindItem(Context context, CachingOptions cachingOptions, String path, boolean withDescriptor) throws InvalidContextException, PathNotFoundException, XmlFileParseException, StoreException {
path = normalizePath(path);
File file = findFile(context, path);
if (file == null) {
return null;
}
Item item = new Item();
item.setName(file.getName());
item.setUrl(path);
item.setFolder(file.isDirectory());
if (withDescriptor) {
File descriptorFile;
// a DOM.
if (file.isFile() && item.getName().endsWith(descriptorFileExtension)) {
item.setDescriptorUrl(path);
descriptorFile = file;
// If it's not a file (a dir) or is not a descriptor (a static asset, like an image), locate the file's
// descriptor by appending a metadata file extension to the file name. If the file exists, load it as
// a DOM.
} else {
String descriptorPath = FilenameUtils.removeExtension(path) + metadataFileExtension;
item.setDescriptorUrl(descriptorPath);
descriptorFile = findFile(context, descriptorPath);
if (descriptorFile != null && !descriptorFile.isFile()) {
throw new StoreException("Descriptor file at " + descriptorFile + " is not really a file");
}
}
if (descriptorFile != null) {
try {
InputStream fileInputStream = new BufferedInputStream(descriptorFile.getInputStream());
Reader fileReader = new InputStreamReader(fileInputStream, charset);
try {
item.setDescriptorDom(createXmlReader().read(fileReader));
} finally {
IOUtils.closeQuietly(fileReader);
}
} catch (IOException e) {
throw new StoreException("Unable to open input stream for descriptor file at " + descriptorFile, e);
} catch (DocumentException e) {
throw new XmlFileParseException("Error while parsing xml document at " + descriptorFile, e);
}
}
}
return item;
}
use of org.dom4j.DocumentException in project core by craftercms.
the class Dom4JDocumentJsonSerializerTest method setUpTestDocument.
private void setUpTestDocument() throws SAXException {
SAXReader reader = new SAXReader();
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
try {
document = reader.read(new StringReader(XML));
} catch (DocumentException e) {
}
}
use of org.dom4j.DocumentException in project summer by foxsugar.
the class PayUtil method readStringXmlOut.
/**
* @description 将xml字符串转换成map
* @param xml
* @return Map
*/
public static Map readStringXmlOut(String xml) {
Map map = new HashMap();
Document doc = null;
try {
// 将字符串转为XML
doc = DocumentHelper.parseText(xml);
// 获取根节点
Element rootElt = doc.getRootElement();
// 拿到根节点的名称
System.out.println("根节点:" + rootElt.getName());
// 获取根节点下的子节点head
Iterator iter = rootElt.elementIterator("head");
// 遍历head节点
while (iter.hasNext()) {
Element recordEle = (Element) iter.next();
// 拿到head节点下的子节点title值
String title = recordEle.elementTextTrim("title");
System.out.println("title:" + title);
map.put("title", title);
// 获取子节点head下的子节点script
Iterator iters = recordEle.elementIterator("script");
// 遍历Header节点下的Response节点
while (iters.hasNext()) {
Element itemEle = (Element) iters.next();
// 拿到head下的子节点script下的字节点username的值
String username = itemEle.elementTextTrim("username");
String password = itemEle.elementTextTrim("password");
System.out.println("username:" + username);
System.out.println("password:" + password);
map.put("username", username);
map.put("password", password);
}
}
// 获取根节点下的子节点body
Iterator iterss = rootElt.elementIterator("body");
// 遍历body节点
while (iterss.hasNext()) {
Element recordEless = (Element) iterss.next();
// 拿到body节点下的子节点result值
String result = recordEless.elementTextTrim("result");
System.out.println("result:" + result);
// 获取子节点body下的子节点form
Iterator itersElIterator = recordEless.elementIterator("form");
// 遍历Header节点下的Response节点
while (itersElIterator.hasNext()) {
Element itemEle = (Element) itersElIterator.next();
// 拿到body下的子节点form下的字节点banlce的值
String banlce = itemEle.elementTextTrim("banlce");
String subID = itemEle.elementTextTrim("subID");
System.out.println("banlce:" + banlce);
System.out.println("subID:" + subID);
map.put("result", result);
map.put("banlce", banlce);
map.put("subID", subID);
}
}
} catch (DocumentException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
Aggregations