Relax NG 在Odoo中的应用
想必有些同学一定会奇怪,Odoo是如何将模块中的XML中的诸如record、menuitem是如何被组织和定义的,以及各种field的各种属性究竟有哪些,今天,我们就来一探究竟。
Relax NG:“可扩展标记语言的下一代正规语言”是一种基于语法的可扩展标记语言模式语言,可用于描述、定义和限制 可扩展标记语言(标准通用标记语言的子集)词汇表。简单地说 Relax NG是解释XML如何被定义的一套XML。Odoo就是通过定义了一套rng文件定义了自己一套xml框架结构,在模块被安装或者升级的时候将其解析成与之相对应的内置对象,存储在数据库中。关于Relax NG的语法规则,可以参考Relax NG的官网。
解析XML文件的代码在convert.py的convert_xml_import方法中:
def convert_xml_import(cr, module, xmlfile, idref=None, mode='init', noupdate=False, report=None):
doc = etree.parse(xmlfile)
relaxng = etree.RelaxNG(
etree.parse(os.path.join(config['root_path'],'import_xml.rng' )))
try:
relaxng.assert_(doc)
except Exception:
_logger.error('The XML file does not fit the required schema !')
_logger.error(misc.ustr(relaxng.error_log.last_error))
raise if idref is None:
idref={}
obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate)
obj.parse(doc.getroot(), mode=mode)
return True
而在xml_import方法中,处理了我们常见的各种节点:menuitem,record,template,url等等。
通过对rng文件的解读,我们可以总结Odoo xml的架构如下:
顶级节点:openerp
二级节点:元素(可多个):data
属性 (可选): noupdate、context
三级节点:元素(可多个):menuitem、record、template、delete、act_window、url、assert、report、workflow、function、ir_set
常见节点属性:
menuitem:id(必填),name,parent,action,sequence,groups,icon,web_icon,web_icon_hover,string
record:id(可选),forcecreate(可选),model,context(可选),
子节点:field(可多个)
template:id,t-name,name,forecreate,context,priority,inherit_id,primary,groups,active,customzie_show,page
delete:model,id,search
act_window:id,name,res_model,domain,src_model,context,view_id,view_type,view_mode,multi,target,key2,groups,limit,usage,auto_refresh
url:id,name,url,target
assert:model,search,count,string,id,context,severity,test
report:id,string,model,name,report_type,multi,menu,keyword,rml,file,sxw,xml,xsl,parser,auto,header,webkit_header,attachment,attachment_use,groups,usage
workflow:model,action,uid,context,ref,value
function:model,name,id,context,eval
ir_set:子节点:field
同样地,在View中也同样用到了Relax NG组织定义了View的架构,具体参见我的另一篇文章:
http://www.cnblogs.com/kfx2007/p/5478375.html
最新文章
- D2.Reactjs 操作事件、状态改变、路由
- 面试:浅谈tcp/udp
- ie下的onscroll和onresize的优化
- 精确到秒的JQuery日期控件
- opencv 构造训练器
- Arduino 3G shield using SoftwareSerial to control
- word:Can't find the word document templant:WordToRqm.doc
- JS for循环有关变量类型的问题/魔兽世界样式的tooltip
- 软件测试面试必问--bug交互流程
- Html.Raw用法
- Mac+sublime text+skim
- jsp使用cookie自动登录
- \r\n
- QWidget窗口类
- ubuntu 安装pptp
- 关于控制反转(IOC)容器 ,依赖注入(DI)模式必读文章收集
- Linux系统性能优化
- JS location.href跳出框架打开新页面
- 解题:POI 2009 Fire Extinguishers
- COM的一些基本概念