java document to xml_Java Document.asXML方法代碼示例

本文整理匯總了Java中org.dom4j.Document.asXML方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.asXML方法的具體用法?Java Document.asXML怎麽用?Java Document.asXML使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.Document的用法示例。

在下文中一共展示了Document.asXML方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: parseDto2XmlHasHead

​點讚 3

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;

}

開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:25,

示例2: parseDto2XmlHasHead

​點讚 3

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;

}

開發者ID:guokezheng,項目名稱:automat,代碼行數:25,

示例3: emitValue

​點讚 3

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);

}

}

開發者ID:IoTKETI,項目名稱:IPE-LWM2M,代碼行數:19,

示例4: testdeployDefinition

​點讚 3

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);

}

開發者ID:alibaba,項目名稱:bulbasaur,代碼行數:20,

示例5: testdeployDefinition

​點讚 3

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);

}

開發者ID:alibaba,項目名稱:bulbasaur,代碼行數:22,

示例6: toDsml

​點讚 2

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();

}

開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:34,

示例7: getNameSpaceInfo

​點讚 2

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("", Pattern.MULTILINE);

Matcher m = p.matcher(xml);

if (!m.find()) {

prtln("root Element not found!?: " + p.toString());

return "";

}

else {

return m.group(1);

}

}

開發者ID:NCAR,項目名稱:joai-project,代碼行數:23,

示例8: getLocalizedDocStr

​點讚 2

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();

}

開發者ID:NCAR,項目名稱:joai-project,代碼行數:11,

示例9: testPersistParser

​點讚 2

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());

}

開發者ID:alibaba,項目名稱:bulbasaur,代碼行數:29,

示例10: testMachineRunWithPersistParser

​點讚 2

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"));

}

開發者ID:alibaba,項目名稱:bulbasaur,代碼行數:29,

示例11: stuffId

​點讚 2

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();

}

開發者ID:NCAR,項目名稱:joai-project,代碼行數:61,

示例12: main_buildIncDOS2Xml_Pro

​點讚 2

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 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 proName = FileUtils.readProperties(newzhCNNameProperties);

/**

* 替換,名稱統一

*/

String contentToOne = document.asXML();

Iterator 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);

}

開發者ID:SvenAugustus,項目名稱:Divinity_Original_Sin_2_zhCN,代碼行數:82,

注:本文中的org.dom4j.Document.asXML方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值