免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1301 | 回复: 2
打印 上一主题 下一主题

[函数] 【erlang xmerl利用xpath计算节点总数】 [复制链接]

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-11-22 02:37 |只看该作者 |倒序浏览
  1. 91> {Root,Body}= xmerl_scan:file("interface.xml").   
  2. {{xmlElement,'nf:rpc-reply','nf:rpc-reply',
  3.      {"nf","rpc-reply"},
  4.      {xmlNamespace,[],
  5.          [{"nf",'urn:ietf:params:xml:ns:netconf:base:1.0'},
  6.           {"nxos",'http://www.cisco.com/nxos:1.0'},
  7.           {"mod",'http://www.cisco.com/nxos:1.0:if_manager'}]},
  8.      [],1,
  9.      [{xmlAttribute,'xmlns:nf',[],
  10.           {"xmlns","nf"},
  11.           [],
  12.           [{'nf:rpc-reply',1}],
  13.           1,[],"urn:ietf:params:xml:ns:netconf:base:1.0",false},
  14.       {xmlAttribute,'xmlns:nxos',[],
  15.           {"xmlns","nxos"},
  16.           [],
  17.           [{'nf:rpc-reply',1}],
  18.           2,[],"http://www.cisco.com/nxos:1.0",false},
  19.       {xmlAttribute,'xmlns:mod',[],
  20.           {"xmlns","mod"},
  21.           [],
  22.           [{'nf:rpc-reply',1}],
  23.           3,[],"http://www.cisco.com/nxos:1.0:if_manager",false},
  24.       {xmlAttribute,'message-id',[],[],[],
  25.           [{'nf:rpc-reply',1}],
  26.           4,[],"110",false}],
  27.      [{xmlText,[{'nf:rpc-reply',1}],1,[],"\n   ",text},
  28.       {xmlElement,'nf:data','nf:data',
  29.           {"nf","data"},
  30.           {xmlNamespace,[],
  31.               [{"nf",'urn:ietf:params:xml:ns:netconf:base:1.0'},
  32.                {"nxos",'http://www.cisco.com/nxos:1.0'},
  33.                {"mod",'http://www.cisco.com/nxos:1.0:if_manager'}]},
  34.           [{'nf:rpc-reply',1}],
  35.           2,[],
  36.           [{xmlText,
  37.                [{'nf:data',2},{'nf:rpc-reply',1}],
  38.                1,[],"\n     ",text},
  39.            {xmlElement,'mod:show','mod:show',
  40.                {"mod",[...]},
  41.                {xmlNamespace,...},
  42.                [...],...},
  43.            {xmlText,
  44.                [{'nf:data',2},{'nf:rpc-reply',...}],
  45.                3,[],
  46.                [...],...}],
  47.           [],".",undeclared},
  48.       {xmlText,[{'nf:rpc-reply',1}],3,[],"\n ",text}],
  49.      [],".",undeclared},
  50. "]]>]]> "}
  51. 92> Root.
  52. {xmlElement,'nf:rpc-reply','nf:rpc-reply',
  53.     {"nf","rpc-reply"},
  54.     {xmlNamespace,[],
  55.         [{"nf",'urn:ietf:params:xml:ns:netconf:base:1.0'},
  56.          {"nxos",'http://www.cisco.com/nxos:1.0'},
  57.          {"mod",'http://www.cisco.com/nxos:1.0:if_manager'}]},
  58.     [],1,
  59.     [{xmlAttribute,'xmlns:nf',[],
  60.          {"xmlns","nf"},
  61.          [],
  62.          [{'nf:rpc-reply',1}],
  63.          1,[],"urn:ietf:params:xml:ns:netconf:base:1.0",false},
  64.      {xmlAttribute,'xmlns:nxos',[],
  65.          {"xmlns","nxos"},
  66.          [],
  67.          [{'nf:rpc-reply',1}],
  68.          2,[],"http://www.cisco.com/nxos:1.0",false},
  69.      {xmlAttribute,'xmlns:mod',[],
  70.          {"xmlns","mod"},
  71.          [],
  72.          [{'nf:rpc-reply',1}],
  73.          3,[],"http://www.cisco.com/nxos:1.0:if_manager",false},
  74.      {xmlAttribute,'message-id',[],[],[],
  75.          [{'nf:rpc-reply',1}],
  76.          4,[],"110",false}],
  77.     [{xmlText,[{'nf:rpc-reply',1}],1,[],"\n   ",text},
  78.      {xmlElement,'nf:data','nf:data',
  79.          {"nf","data"},
  80.          {xmlNamespace,[],
  81.              [{"nf",'urn:ietf:params:xml:ns:netconf:base:1.0'},
  82.               {"nxos",'http://www.cisco.com/nxos:1.0'},
  83.               {"mod",'http://www.cisco.com/nxos:1.0:if_manager'}]},
  84.          [{'nf:rpc-reply',1}],
  85.          2,[],
  86.          [{xmlText,
  87.               [{'nf:data',2},{'nf:rpc-reply',1}],
  88.               1,[],"\n     ",text},
  89.           {xmlElement,'mod:show','mod:show',
  90.               {"mod","show"},
  91.               {xmlNamespace,[],...},
  92.               [{...}|...],
  93.               2,...},
  94.           {xmlText,
  95.               [{'nf:data',2},{'nf:rpc-reply',1}],
  96.               3,[],"\n   ",text}],
  97.          [],".",undeclared},
  98.      {xmlText,[{'nf:rpc-reply',1}],3,[],"\n ",text}],
  99.     [],".",undeclared}
  100. 93> xmerl_xpath:string("count(//mod:interface)",Root).
  101. {xmlObj,number,3}
  102. 94>
复制代码

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
2 [报告]
发表于 2015-11-22 03:02 |只看该作者
先把hrl文件读入console,这样显示会更清楚。
  1. rr("xmerl.hrl").
复制代码

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
3 [报告]
发表于 2015-11-22 03:02 |只看该作者
  1. 145>  xmerl_xpath:string("//mod:ip_addr",Root).         
  2. [#xmlElement{
  3.      name = 'mod:ip_addr',expanded_name = 'mod:ip_addr',
  4.      nsinfo = {"mod","ip_addr"},
  5.      namespace =
  6.          #xmlNamespace{
  7.              default = [],
  8.              nodes =
  9.                  [{"nf",'urn:ietf:params:xml:ns:netconf:base:1.0'},
  10.                   {"nxos",'http://www.cisco.com/nxos:1.0'},
  11.                   {"mod",'http://www.cisco.com/nxos:1.0:if_manager'}]},
  12.      parents =
  13.          [{'mod:ROW_interface',2},
  14.           {'mod:TABLE_interface',2},
  15.           {'mod:__readonly__',2},
  16.           {'mod:__XML__OPT_Cmd_show_interface_brief___readonly__',2},
  17.           {'mod:interface',2},
  18.           {'mod:show',2},
  19.           {'nf:data',2},
  20.           {'nf:rpc-reply',1}],
  21.      pos = 6,attributes = [],
  22.      content =
  23.          [#xmlText{
  24.               parents =
  25.                   [{'mod:ip_addr',6},
  26.                    {'mod:ROW_interface',2},
  27.                    {'mod:TABLE_interface',2},
  28.                    {'mod:__readonly__',2},
  29.                    {'mod:__XML__OPT_Cmd_show_interface_brief___readonly__',2},
  30.                    {'mod:interface',2},
  31.                    {'mod:show',2},
  32.                    {'nf:data',2},
  33.                    {'nf:rpc-reply',1}],
  34.               pos = 1,language = [],value = "172.23.152.20",type = text}],
  35.      language = [],xmlbase = ".",elementdef = undeclared}]
  36. 146>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP