word模板和XML数据源是如何合并生成最后的word文档的详细过程
This document is used for consultant or developers at customer side who would like to know technical detail about how a word template is merged with xml data stream. Before you touch the related ABAP code about document merging, it is good to get some basic understandong about how ABAP manipulates word document in this document Manipulate Docx document with ABAP.
In the document Create Webservice enabled word document in attachment assignment block, it is described how to create a word template and feed its content with web service generated via web service tool in CRM Webclient UI. Besides that you could also use your own web service, for example you can expose your function module in ABAP backend via SOAMANAGER. The detailed step could be found in this document.
In consulting note 2048272, an ABAP report is provided to allow you to merge the word template with given xml data without Webclient UI:
If you meet with issue that the merged word document does not work as you expected, for example some fields are empty however the corresponding node in xml do have data filled, then you can use this ABAP report to do trouble shooting. You could get the word template and xml data file for web service response by following consulting note 2047259.
In this document, I will show you how the element “Partner” in word template is merged with the value from xml node SOLD_TO.PARTNER in the runtime. You could find the template “zpartner.docx” and xml data file “response.xml” used in this example from document attachment.
Explore the word template to identify binding information
From the above screenshot, we click on Partner field and the tooltip shows this element is bound to field PARTNER. How is this mapping relationship maintained within word template?
Rename zparetner.docx to zpartner.zip, double click on the zip file, double click subfolder “word”, then double click on “document.xml”: You should find a w:t node with PARTNER, and a w:tag node with attribute “w:val”, whose value is 0050569457471ED488F2038D1D8360BE. The w:t node contains the text which end user sees in the word template, and w:val maintains the mapping relationship to xml schema.
Now go back to zpartner.zip, click on customXml folder and double click “item1.xml”. Search xml file by value “0050569457471ED488F2038D1D8360BE”. One result found, and we could know the complete binding path is Z_JENS_GET_MORE_COMPLEXResponse.ES_C5064266.SOLD_TO.PARTNER.
Merge step1 cl_crm_oi_docx_helper=>replace_vars_uuid_with_path
In this step, the original uuid in document.xml is replaced by the complete path of bound xml node:
Merge step2 add necessary namespace to every node in xml
It is done via transformation call:
CALL TRANSFORMATION crm_office_int_rt_add_ns
SOURCE XML lv_response
RESULT XML lv_response_ns.
Notice the no namespace added for each node after transformation call:
Merge step3 cl_crm_oi_docx_transform_rt=>transform
the formatted template source( uuid replaced with complete path ) and formatted xml data source( n0 namespace added ) are passed into this method.
step3.1 cl_crm_oi_docx_transform_rt=>indicate_tree
The xml node is further enriched with attribute Loopcount and Path, which are especially used for render data with table structure. ( template merged with table data will be discussed in another document )
step3.2 cl_crm_oi_docx_transform_rt=>update_payload_from_addinsch
This method will create a new attribute sapvartype with value “T” for those node in xml source with table structure, not relevant for current example.
step3.3 recursively call cl_crm_oi_docx_transform_rt=>process_node_cc
node: dom element of root node “Z_JENS_GET_MORE_COMPLEXResponse” in xml.
Now we have reached the first leaf node in xml, “CLIENT”. Pay attention to the recursive callstack.
since we don’t bind CLIENT node in xml to our template, after method get_contentcontrol_node_bypath, lt_node_ref_word will remain empty so we quit from the current traverse and try with next node.
Soon we reach the method get_contentcontrol_node_bypath again, and since our template consumes the node PARTNER, it is ready to feed the template with the value contained in this xml node.
The sold to partner id “0000419333” will be set to the corresponding dom element node “lr_node_word” by the method below.
in the beginning of this document we know it is the content of w:t node which will be displayed to end user so first we have to locate those w:t nodes via filtering ( w:t node found and stored in variable node_text ) and finally fill value to them by method fill_text_node, and that’s all.
final merged document:
And you could find the w:t node contains the correct value from document source code:
Next reading
Understand how the word template is merged with xml data stream – part 2 – table structure
- 怎样突破表名30个字符的限制(r2笔记51天)
- C/C++——排序
- 关于move tablespace的问题总结(r2笔记50天)
- 一些极度危险的linux命令(r2笔记49天)
- 挑战数据结构与算法面试题——80题全解析(一)
- 关于操作失误的数据修复(r2笔记48天)
- 挑战数据结构与算法面试题——80题全解析(三)
- 巧用rowid简化sql查询(r2笔记47天)
- 算法类面试题解析——美团2016校招:棋子翻转
- 算法类面试题解析——美团2016校招:最大差值
- 用Python进行机器学习小案例
- 启用ODM极速调优IO (r2笔记66天)
- 通过addm分析io问题(r2笔记64天)
- python爬虫+R数据可视化 实例
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- stripos函数知识点实例分享
- PHP实现字符串大小写转函数的功能实例
- 在django中实现choices字段获取对应字段值
- python语言中有算法吗
- jQuery ajax+PHP实现的级联下拉列表框功能示例
- PHP+mysql防止SQL注入的方法小结
- 浅谈tensorflow 中的图片读取和裁剪方式
- Python实现SMTP邮件发送
- 浅谈多卡服务器下隐藏部分 GPU 和 TensorFlow 的显存使用设置
- 通过PHP设置BugFree获取邮箱通知
- Django封装交互接口代码
- 使用K.function()调试keras操作
- tensorflow图像裁剪进行数据增强操作
- ThinkPHP3.2.3框架Memcache缓存使用方法实例总结
- Python+PyQt5+MySQL实现天气管理系统