想必有些同学一定会奇怪,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

最新文章

  1. D2.Reactjs 操作事件、状态改变、路由
  2. 面试:浅谈tcp/udp
  3. ie下的onscroll和onresize的优化
  4. 精确到秒的JQuery日期控件
  5. opencv 构造训练器
  6. Arduino 3G shield using SoftwareSerial to control
  7. word:Can't find the word document templant:WordToRqm.doc
  8. JS for循环有关变量类型的问题/魔兽世界样式的tooltip
  9. 软件测试面试必问--bug交互流程
  10. Html.Raw用法
  11. Mac+sublime text+skim
  12. jsp使用cookie自动登录
  13. \r\n
  14. QWidget窗口类
  15. ubuntu 安装pptp
  16. 关于控制反转(IOC)容器 ,依赖注入(DI)模式必读文章收集
  17. Linux系统性能优化
  18. JS location.href跳出框架打开新页面
  19. 解题:POI 2009 Fire Extinguishers
  20. COM的一些基本概念

热门文章

  1. JS 时间格式化
  2. 【RQNOJ356】myt的格斗
  3. 一个简单的Object Hook的例子(win7 32bit)
  4. mysql中sql语句
  5. hdu 5306 优先队列
  6. SpringHttpInvoker解析1-使用示例
  7. POJ 1971 统计平行四边形 HASH
  8. 为什么网页通常把JS调用放在底部?
  9. 学习笔记总结---关于sass
  10. asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例