本文整理汇总了Java中org.dom4j.DocumentHelper.createDocument方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentHelper.createDocument方法的具体用法?Java DocumentHelper.createDocument怎么用?Java DocumentHelper.createDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.DocumentHelper
的用法示例。
在下文中一共展示了DocumentHelper.createDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseList2XmlBasedNode
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
* 将List数据类型转换为符合XML格式规范的字符串(基于节点值的方式)
*
* @param pList 传入的List数据(List对象可以是Dto、VO、Domain的属性集)
* @param pRootNodeName 根节点名称
* @param pFirstNodeName 行节点名称
* @return string 返回XML格式字符串
*/
public static final String parseList2XmlBasedNode(List pList, String pRootNodeName, String pFirstNodeName) {
Document document = DocumentHelper.createDocument();
Element output = document.addElement(pRootNodeName);
for (int i = 0; i < pList.size(); i++) {
Map map = (Map) pList.get(i);
Element elRow = output.addElement(pFirstNodeName);
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
Element leaf = elRow.addElement((String) entry.getKey());
leaf.setText(String.valueOf(entry.getValue()));
}
}
String outXml = document.asXML().substring(39);
return outXml;
}
示例2: parseList2Xml
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
* 将List数据类型转换为符合XML格式规范的字符串(基于节点属性值的方式)
*
* @param pList 传入的List数据(List对象可以是Dto、VO、Domain的属性集)
* @param pRootNodeName 根节点名称
* @param pFirstNodeName 行节点名称
* @return string 返回XML格式字符串
*/
public static final String parseList2Xml(List pList, String pRootNodeName, String pFirstNodeName) {
Document document = DocumentHelper.createDocument();
Element elRoot = document.addElement(pRootNodeName);
for (int i = 0; i < pList.size(); i++) {
Map map = (Map) pList.get(i);
Element elRow = elRoot.addElement(pFirstNodeName);
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
elRow.addAttribute((String) entry.getKey(), String.valueOf(entry.getValue()));
}
}
String outXml = document.asXML().substring(39);
return outXml;
}
示例3: parseDto2Xml
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
* 将Dto转换为符合XML标准规范格式的字符串(基于节点值形式)
*
* @param map 传入的Dto对象
* @param pRootNodeName 根结点名
* @return string 返回XML格式字符串
*/
public static final String parseDto2Xml(Map map, String pRootNodeName) {
Document document = DocumentHelper.createDocument();
// 增加一个根元素节点
document.addElement(pRootNodeName);
Element root = document.getRootElement();
Iterator keyIterator = map.keySet().iterator();
while (keyIterator.hasNext()) {
String key = (String)keyIterator.next();
String value = (String)map.get(key);
Element leaf = root.addElement(key);
leaf.setText(value);
}
// 将XML的头声明信息截去
String outXml = document.asXML().substring(39);
return outXml;
}
示例4: parseDto2Xml
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
* 将Dto转换为符合XML标准规范格式的字符串(基于节点值形式)
*
* @param dto 传入的Dto对象
* @param pRootNodeName 根结点名
* @return string 返回XML格式字符串
*/
public static final String parseDto2Xml(Map map, String pRootNodeName) {
Document document = DocumentHelper.createDocument();
// 增加一个根元素节点
document.addElement(pRootNodeName);
Element root = document.getRootElement();
Iterator keyIterator = map.keySet().iterator();
while (keyIterator.hasNext()) {
String key = (String) keyIterator.next();
String value = (String) map.get(key);
Element leaf = root.addElement(key);
leaf.setText(value);
}
// 将XML的头声明信息截去
String outXml = document.asXML().substring(39);
return outXml;
}
示例5: emitValue
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private void emitValue(String path, String content){
Document document = DocumentHelper.createDocument();
Element eleRoot = document.addElement("msg");
Element elePath = eleRoot.addElement("path");
Element eleContent = eleRoot.addElement("value");
elePath.setText(path);
eleContent.setText(content);
String msg = document.asXML();
if(handler != null){
MsgReceiveEvent event = new MsgReceiveEvent(this, msg);
handler.receiveMsgEvent(event);
}
}
示例6: setInfo
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public void setInfo(TimetableInfo info, TimetableInfoFileProxy proxy) {
if (info.saveToFile()) {
FileInfo fInfo = new FileInfo();
String defName = null;
if (getDefinition()!=null) {
defName = getDefinition().getName();
} else {
defName = info.getClass().getName();
if (defName.indexOf('.')>=0)
defName = defName.substring(defName.lastIndexOf('.')+1);
}
fInfo.setName(defName+"_"+generateId()+".zxml");
fInfo.saveInfo(info, proxy);
info = fInfo;
}
Document document = DocumentHelper.createDocument();
Element root = document.addElement(info.getClass().getName());
info.save(root);
setValue(document);
setCached(getUniqueId(), info);
}
示例7: main
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public static void main(String args[]){
Namespace rootNs = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri
QName rootQName = QName.get("workflow-app", rootNs); // your root element's name
Element workflow = DocumentHelper.createElement(rootQName);
Document doc = DocumentHelper.createDocument(workflow);
workflow.addAttribute("name", "test");
Element test = workflow.addElement("test");
test.addText("hello");
OutputFormat outputFormat = OutputFormat.createPrettyPrint();
outputFormat.setEncoding("UTF-8");
outputFormat.setIndent(true);
outputFormat.setIndent(" ");
outputFormat.setNewlines(true);
try {
StringWriter stringWriter = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(stringWriter);
xmlWriter.write(doc);
xmlWriter.close();
System.out.println( doc.asXML() );
System.out.println( stringWriter.toString().trim());
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例8: createBooleanQueryElement
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private static Element createBooleanQueryElement(String type, List clauseElements) throws Exception {
if (type == null || (!type.equals("OR") && !type.equals("AND")))
throw new Exception("boolean type must be either 'OR' or 'AND'");
if (clauseElements == null || clauseElements.size() == 0)
throw new Exception("boolean clause Elements List is empty or null");
Document document = DocumentHelper.createDocument();
Element booleanQuery = document.addElement("booleanQuery ");
booleanQuery.addAttribute("type", type);
for (int i = 0; i < clauseElements.size(); i++)
booleanQuery.add((Element) clauseElements.get(i));
return booleanQuery;
}
示例9: VersionedDocument
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public VersionedDocument() {
wrapped = DocumentHelper.createDocument();
}
示例10: extractIncrement
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
* 根据节点数据,生成增量文本xml
*
* @param list 节点数据
* @param buildNew 替换新文本
* @param printAll 是否打印结果
* @return
* @throws Exception
*/
@Override
public Document extractIncrement(List<? extends NodeResult> list, boolean buildNew, boolean print)
throws Exception {
Element root = DocumentHelper.createElement("contentList");
Iterator<?> it = list.iterator();
boolean first100 = true, first80 = true, first50 = true, first25 = true, first15 = true,
first5 = true, first = true;
if (print) {
if (buildNew) {
System.out.println("----------------------------左边是增量文本,右边是原文本-----------------");
} else {
System.out.println("----------------------------左边是原文本,右边是增量文本-----------------");
}
}
while (it.hasNext()) {
NodeResult nodeResult = (NodeResult) it.next();
Element e = DocumentHelper.createElement("content");
e.addAttribute("contentuid", nodeResult.getContentuid());
e.setText(buildNew ? nodeResult.getNewText() : nodeResult.getText());
if (print) {
if (nodeResult instanceof DiffResult) {
DiffResult res = (DiffResult) nodeResult;
if (first100 && res.getDifference() >= 1.0) {
System.out.println("----------------------------差异超过100%的文本-----------------");
first100 = false;
}
if (first80 && res.getDifference() < 1.0 && res.getDifference() > 0.8) {
System.out.println("\n\n----------------------------差异超过80%的文本-----------------");
first80 = false;
}
if (first50 && res.getDifference() <= 0.8 && res.getDifference() > 0.5) {
System.out.println("\n\n----------------------------差异超过50%的文本-----------------");
first50 = false;
}
if (first25 && res.getDifference() <= 0.5 && res.getDifference() > 0.25) {
System.out.println("\n\n----------------------------差异超过25%的文本-----------------");
first25 = false;
}
if (first15 && res.getDifference() <= 0.25 && res.getDifference() > 0.15) {
System.out.println("\n\n----------------------------差异超过15%的文本-----------------");
first15 = false;
}
if (first5 && res.getDifference() <= 0.15 && res.getDifference() > 0.05) {
System.out.println("\n\n----------------------------差异超过5%的文本-----------------");
first5 = false;
}
if (first && res.getDifference() < 0.05) {
System.out.println("\n\n----------------------------差异低于5%的文本-----------------");
first = false;
}
}
System.out.println(nodeResult.getContentuid() + "="
+ (buildNew ? (nodeResult.getText() + "|" + nodeResult.getNewText())
: (nodeResult.getNewText() + "|" + nodeResult.getText())));
}
root.add(e);
}
Document doc = DocumentHelper.createDocument(root);
return doc;
}
示例11: addChildNodeTest
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
@Test
public void addChildNodeTest() throws IOException, SAXException, TransformerException {
Document doc = DocumentHelper.createDocument(DocumentHelper.createElement("root"));
xmlBuilder.addNode(doc, "/root/child", "test value", uris.get("ARCLIB"));
assertThat(doc.asXML(), is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root><child xmlns=\"http://arclib.lib.cas.cz/ARCLIB_XML\">test value</child></root>"));
}
示例12: CollectionAdopter
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
* Constructor for the CollectionAdopter object
*
* @param mdpHandle NOT YET DOCUMENTED
* @exception Exception NOT YET DOCUMENTED
*/
public CollectionAdopter(String mdpHandle) throws Exception {
SimpleNdrRequest.setDebug(true);
SimpleNdrRequest.setVerbose(false);
MetadataProviderReader mdp = new MetadataProviderReader(mdpHandle);
List itemHandles = mdp.getItemHandles();
prtln("There are " + itemHandles.size() + " records to retrieve");
for (Iterator i = itemHandles.iterator(); i.hasNext(); ) {
String itemHandle = (String) i.next();
MetadataReader mdReader = new MetadataReader(itemHandle);
// prtln ("\n" + mdReader.getHandle());
Element nsdl_dc_stream = (mdReader.getDataStream("nsdl_dc"));
// pp (nsdl_dc_stream);
// prtln ("----------");
Element ncs_item_stream = this.getNcsItemStream(nsdl_dc_stream);
// pp (ncs_item_stream);
Element root = DocumentHelper.createElement("ndrMetadataInfo");
Element ndrHandle_element = root.addElement("ndrHandle");
ndrHandle_element.setText(itemHandle);
Element nsdl_dc_element = root.addElement("nsdl_dc");
if (nsdl_dc_stream != null)
nsdl_dc_element.add(nsdl_dc_stream);
Element ncs_item_element = root.addElement("ncs_item");
if (ncs_item_stream != null)
ncs_item_element.add(ncs_item_stream);
Document doc = DocumentHelper.createDocument(root);
// pp (doc);
this.writeDoc(doc);
}
}
示例13: addAttributeTest
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
@Test
public void addAttributeTest() throws IOException, SAXException, TransformerException {
Document doc = DocumentHelper.createDocument(DocumentHelper.createElement("root"));
xmlBuilder.addNode(doc, "/root/@testAttribute", "test value", uris.get("ARCLIB"));
assertThat(doc.asXML(), is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root testAttribute=\"test value\"/>"));
}
示例14: makeJsonError
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private String makeJsonError (String msg) {
Element err = DocumentHelper.createElement ("error");
if (msg == null)
msg = "unknown error";
err.setText(msg);
Document responseDoc = DocumentHelper.createDocument(err);
try {
org.json.JSONObject json = org.json.XML.toJSONObject(responseDoc.asXML());
return json.toString();
} catch (Throwable e) {
prtlnErr ("WARNING: unable to construct json error structure");
}
return "error";
}
示例15: execute
import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public void execute(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
Set<String> keySet = Configure.getStore().keySet();
Document dom = DocumentHelper.createDocument();
Element properties = dom.addElement("properties");
Element categoryElement = properties.addElement("category");
Element nameElement = categoryElement.addElement("name");
nameElement.setText("BDF2");
for (String entry : keySet) {
Element propertyElement = categoryElement.addElement("property");
Element element = propertyElement.addElement("key");
element.setText(entry);
element = propertyElement.addElement("value");
element.setText(Configure.getStore().getString(entry));
element = propertyElement.addElement("comment");
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml;charset=utf8");
PrintWriter pw = response.getWriter();
pw.print(dom.asXML());
}