本文整理匯總了Java中org.dom4j.Document.asXML方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.asXML方法的具體用法?Java Document.asXML怎麽用?Java Document.asXML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.Document
的用法示例。
在下文中一共展示了Document.asXML方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseDto2XmlHasHead
import org.dom4j.Document; //導入方法依賴的package包/類
/**
* 將Dto轉換為符合XML標準規範格式的字符串(基於節點值形式)
*
* @param map 傳入的Dto對象
* @param pRootNodeName 根結點名
* @return string 返回XML格式字符串
*/
public static final String parseDto2XmlHasHead(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);
String outXml = document.asXML();
return outXml;
}
示例2: parseDto2XmlHasHead
import org.dom4j.Document; //導入方法依賴的package包/類
/**
* 將Dto轉換為符合XML標準規範格式的字符串(基於節點值形式)
*
* @param dto 傳入的Dto對象
* @param pRootNodeName 根結點名
* @return string 返回XML格式字符串
*/
public static final String parseDto2XmlHasHead(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);
String outXml = document.asXML();
return outXml;
}
示例3: emitValue
import org.dom4j.Document; //導入方法依賴的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);
}
}
示例4: testdeployDefinition
import org.dom4j.Document; //導入方法依賴的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);
}
示例5: testdeployDefinition
import org.dom4j.Document; //導入方法依賴的package包/類
@Test
public void testdeployDefinition() {
// 初始化
SAXReader reader = new SAXReader();
// 拿不到信息
//URL url = this.getClass().getResource("/multipleTask.xml");
URL url = this.getClass().getResource("/singleTask.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("singleTask", "測試單人任務流程", definitionContent, true);
//DefinitionHelper.getInstance().deployDefinition("multipleTask", "測試多人任務流程", definitionContent, true);
}
示例6: stuffId
import org.dom4j.Document; //導入方法依賴的package包/類
/**
* Place the provided ID into the provided recordXml. recordXml must be
* "delocalized" - it must contain namespace information in the rootElement. Currently supported xmlFormats
are "adn" and "news_opps".
*
*@param recordXml Description of the Parameter
*@param id Description of the Parameter
*@return Description of the Return Value
*@exception Exception Description of the Exception
*/
public static String stuffId(String recordXml, String xmlFormat, String id)
throws Exception {
// prtln ("stuffId: \n\trecordXml: " + recordXml + "\n\txmlFormat: " + xmlFormat + "\n\tid: " + id);
String idPath;
if (xmlFormat.equals("adn"))
idPath = "/itemRecord/metaMetadata/catalogEntries/catalog/@entry";
else if (xmlFormat.equals("news_opps"))
idPath = "/news-oppsRecord/recordID";
else if (xmlFormat.equals("dlese_anno"))
idPath = "/annotationRecord/service/recordID";
else
throw new Exception ("unsupported metadataformat: " + xmlFormat);
// create a localized Document from the xmlString
Document doc = Dom4jUtils.getXmlDocument(recordXml);
if (doc == null)
throw new Exception ("could not parse provided recordXML");
Element rootElement = doc.getRootElement();
if (rootElement == null)
throw new Exception ("root element not found");
String rootElementName = rootElement.getName();
if (rootElementName == null || rootElementName.length() == 0)
throw new Exception ("rootElementName not found");
String nameSpaceInfo = Dom4jUtils.getNameSpaceInfo(doc, rootElementName);
if (nameSpaceInfo == null || nameSpaceInfo.trim().length() == 0) {
throw new Exception("recordXml does not contain required name space information in the root element");
}
doc = Dom4jUtils.localizeXml (doc, rootElementName);
if (doc == null)
throw new Exception ("doc could not be localized - please unsure the record's root element contains namespace information");
DocMap docMap = new DocMap (doc);
try {
docMap.smartPut(idPath, id);
} catch (Exception e) {
throw new Exception ("Unable to insert ID: " + e.getMessage());
}
doc = Dom4jUtils.delocalizeXml(doc, rootElementName, nameSpaceInfo);
if (doc == null) {
throw new Exception("not able to delocalize xml");
}
// prtln (Dom4jUtils.prettyPrint(doc));
return doc.asXML();
}
示例7: toDsml
import org.dom4j.Document; //導入方法依賴的package包/類
/**
* Converts this Batch Response to its XML representation in the DSMLv2 format.
*
* @param prettyPrint if true, formats the document for pretty printing
* @return the XML representation in DSMLv2 format
*/
public String toDsml( boolean prettyPrint )
{
Document document = DocumentHelper.createDocument();
Element element = document.addElement( "batchResponse" );
element.add( ParserUtils.DSML_NAMESPACE );
element.add( ParserUtils.XSD_NAMESPACE );
element.add( ParserUtils.XSI_NAMESPACE );
// RequestID
if ( requestID != 0 )
{
element.addAttribute( "requestID", Integer.toString( requestID ) );
}
for ( DsmlDecorator<? extends Response> response : responses )
{
response.toDsml( element );
}
if ( prettyPrint )
{
document = ParserUtils.styleDocument( document );
}
return document.asXML();
}
示例8: getNameSpaceInfo
import org.dom4j.Document; //導入方法依賴的package包/類
/**
* Gets the nameSpaceInfo associated with the root element of a Document. Returns all contents of the root
* Element except the element name.
*
* @param doc Description of the Parameter
* @param rootElementName Description of the Parameter
* @return The nameSpaceInfo value
*/
public static String getNameSpaceInfo(Document doc, String rootElementName) {
String xml = doc.asXML();
String elementName = rootElementName;
Pattern p = Pattern.compile("<" + rootElementName + "(.+?)>", Pattern.MULTILINE);
Matcher m = p.matcher(xml);
if (!m.find()) {
prtln("root Element not found!?: " + p.toString());
return "";
}
else {
return m.group(1);
}
}
示例9: getLocalizedDocStr
import org.dom4j.Document; //導入方法依賴的package包/類
/**
* returns xmlRecord with namespace info removed for the purpose of testing error handling
*/
private static String getLocalizedDocStr (String recordXml) throws Exception {
Document doc = Dom4jUtils.getXmlDocument (recordXml);
String rootElementName = doc.getRootElement().getName();
String nameSpaceInfo = Dom4jUtils.getNameSpaceInfo(doc, rootElementName);
doc = Dom4jUtils.localizeXml(doc, rootElementName);
return doc.asXML();
}
示例10: testPersistParser
import org.dom4j.Document; //導入方法依賴的package包/類
@Test
public void testPersistParser() {
// deploy 2 version of definition first
SAXReader reader = new SAXReader();
// 拿不到信息
URL url = this.getClass().getResource("/persist_definition.xml");
Document document = null;
try {
document = reader.read(url);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String definitionContent = document.asXML();
DefinitionHelper.getInstance().deployDefinition("persist_definition", "測試", definitionContent, true);
DefinitionHelper.getInstance().deployDefinition("persist_definition", "測試", definitionContent, true);
Definition definition = persistParser.parse("persist_definition", 0);
Assert.assertEquals("persist_definition", definition.getName());
Assert.assertEquals(2, definition.getVersion());
Assert.assertNotNull(definition.getState("i'm start"));
Definition definition1 = persistParser.parse("persist_definition", 1);
Assert.assertEquals(1, definition1.getVersion());
}
示例11: testMachineRunWithPersistParser
import org.dom4j.Document; //導入方法依賴的package包/類
@Test
public void testMachineRunWithPersistParser() {
SAXReader reader = new SAXReader();
// 拿不到信息
URL url = this.getClass().getResource("/persist_definition.xml");
Document document = null;
try {
document = reader.read(url);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String definitionContent = document.asXML();
int definitionVersion = DefinitionHelper.getInstance().deployDefinition("persist_definition","測試", definitionContent,
true).getDefinitionVersion();
PersistMachine p = persistMachineFactory.newInstance(String.valueOf(System.currentTimeMillis()),
"persist_definition");
Assert.assertEquals(definitionVersion, p.getProcessVersion());
Map m = new HashMap();
m.put("goto", 2);
m.put("_i", 3);
p.addContext(m);
p.run();
Assert.assertEquals(6, p.getContext("_a"));
}
示例12: main_buildIncDOS2Xml_Pro
import org.dom4j.Document; //導入方法依賴的package包/類
/**
* 自動化優化個人的漢化文本,輸出增量文本english_2.xml(麵板、技能的文本優化) english_3.xml(名字統一文本)
*
* @throws Exception
*/
private static void main_buildIncDOS2Xml_Pro(String xml, String newzhCNProperties,
String newzhCNNameProperties, boolean printAll, boolean replaceSpace,
int autoMaxDiffereceLimit, boolean backup) throws Exception {
System.out.println("-------------------以下是english_2.xml(麵板、技能的文本優化)-----------------------");
/**
* 讀取遊戲3dm漢化的初步english.xml文件
*/
Document document = FileUtils.readDocument(xml);
/**
* 讀取properties文件,裏麵包含新的優化的漢化文本映射
*/
Map<String, String> pro = FileUtils.readProperties(newzhCNProperties);
Document documentInc = DocumentHelper.parseText(document.asXML());
/**
* 替換DOS2神界原罪2的漢化文本為新的漢化文本
*/
documentInc = documentReplace.replaceAll(documentInc, pro);
String content = documentInc.asXML();
documentInc = DocumentHelper.parseText(content);
/**
* 提取增量文本
*/
documentInc =
documentExtract.extractIncrement(document, documentInc, autoMaxDiffereceLimit, printAll);
String english_2 = FileUtils.getFilePathInSameDir(xml, "english_2.xml");
/**
* 備份english_2.xml文件
*/
if (backup)
FileUtils.backup(english_2);
/**
* documentInc 寫入新的DOS2神界原罪2文件,不需要xml頭
*/
FileUtils.writerDocumentToNewDOS2File(documentInc, english_2);
System.out.println("\n\n\n-------------------以下是english_3.xml(名字統一文本)-----------------------");
/**
* 讀取properties文件,裏麵包含統一名稱
*/
Map<String, String> proName = FileUtils.readProperties(newzhCNNameProperties);
/**
* 替換,名稱統一
*/
String contentToOne = document.asXML();
Iterator<String> it = proName.keySet().iterator();
while (it.hasNext()) {
String name = (String) it.next();
String newName = proName.get(name);
if (newName != null && !"".equals(newName)) {
contentToOne = contentToOne.replaceAll(name, newName);
}
}
Document documentToOne = DocumentHelper.parseText(contentToOne);
/**
* 替換空格
*/
if (replaceSpace)
documentToOne = TextUtils.replaceSpace(documentToOne);
/**
* 提取增量文本
*/
documentToOne =
documentExtract.extractIncrement(document, documentToOne, autoMaxDiffereceLimit, printAll);
String english_3 = FileUtils.getFilePathInSameDir(xml, "english_3.xml");
/**
* 備份english_3.xml文件
*/
if (backup)
FileUtils.backup(english_3);
/**
* documentToOne 寫入新的DOS2神界原罪2文件,不需要xml頭
*/
FileUtils.writerDocumentToNewDOS2File(documentToOne, english_3);
}