当前位置: 首页>>代码示例>>Java>>正文


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

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,代码来源:XmlUtil.java

示例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;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:25,代码来源:XmlUtil.java

示例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);
    }
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:19,代码来源:SimpleLwm2mServer.java

示例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);
}
 
开发者ID:alibaba,项目名称:bulbasaur,代码行数:20,代码来源:PersistDefinationTest.java

示例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);
}
 
开发者ID:alibaba,项目名称:bulbasaur,代码行数:22,代码来源:TaskTest.java

示例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();
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:61,代码来源:WebServiceClient.java

示例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();
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:34,代码来源:BatchResponseDsml.java

示例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);
	}
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:23,代码来源:Dom4jUtils.java

示例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();
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:11,代码来源:DCSServiceTester.java

示例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());
}
 
开发者ID:alibaba,项目名称:bulbasaur,代码行数:29,代码来源:PersistParserTest.java

示例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"));
}
 
开发者ID:alibaba,项目名称:bulbasaur,代码行数:29,代码来源:PersistParserTest.java

示例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);
}
 
开发者ID:SvenAugustus,项目名称:Divinity_Original_Sin_2_zhCN,代码行数:82,代码来源:DOS2zhCNMain.java


注:本文中的org.dom4j.Document.asXML方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。