word模板和XML数据源是如何合并生成最后的word文档的详细过程-阿里云开发者社区

开发者社区> jerrywangsap> 正文

word模板和XML数据源是如何合并生成最后的word文档的详细过程

简介: 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:


image.png


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.


image.png


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.


image.png


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.


image.png


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:image.png


Notice the no namespace added for each node after transformation call:


image.png


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 )


image.png


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.


image.png


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.


image.png



Now we have reached the first leaf node in xml, “CLIENT”. Pay attention to the recursive callstack.


image.png


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.



image.png

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.


image.png


The sold to partner id “0000419333” will be set to the corresponding dom element node “lr_node_word” by the method below.


image.png


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.


image.png


final merged document:


image.png


And you could find the w:t node contains the correct value from document source code:


image.png


Next reading

Understand how the word template is merged with xml data stream – part 2 – table structure


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
vscode编辑器怎么用代码片段生成用户的文件模板?
vscode编辑器怎么用代码片段生成用户的文件模板?
546 0
LINQ 从数据库读数据生成 XML
本实例是一个从数据库里读出来省份,城市,地区的数据生成3个XML文件. 首先创建一个Linq to SQL的类, 然后将省份,城市,地区的表拖入类中: 然后新建一个类,加入代码如下:         public void ResetProvinces(string path)       ...
618 0
使用 WordPress 插件模板开发高质量插件
  WordPress 插件样板是标准化的,有组织的,面向对象的基础,用于构建高品质的 WordPress 插件。样板遵循编码标准和文件标准,所以你不必自己学习这些,根据注释编写代码即可。     官方网站      源码下载   您可能感兴趣的相关文章 网站开发中很有用的 j...
590 0
VS2010 生成Xml格式的注释文档
项目, 属性, build, 勾选xml document file, 重新build, 即可生成xml注释文件, 然后还得找工具软件(看到anytao推荐SandCastle) 生成更易读的帮助文档.   作者:BobLiu 邮箱:lzd_ren@hotmail.com 出处:http://www.cnblogs.com/liuzhendong 本文版权归作者所有,欢迎转载,未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
704 0
+关注
2627
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载