初次使用xmerl

初次使用xmerl

在官方文档上看到

 

There are two known shortcomings in xmerl:

It cannot retrieve external entities on the Internet by a URL reference, only resources in the local file system.

xmerl can parse Unicode encoded data. But, it fails on tag names, attribute names and other mark-up names that are encoded Unicode characters not mapping on ASCII.

让我有点失望,幸好有xmerl_scan:string/2和xmerl_xpath:string/2

 

简单代码 解析一个xml字符串,转换后提取code的value.

140 assertMatch(A,Code)->
141     {ParsedDocumentRootElement,_RemainningText}=xmerl_scan:string(A),
142     Str = lists:concat(["/result[@code='",Code,"']"]),
143     Result = xmerl_xpath:string(Str,ParsedDocumentRootElement),
144     [Re|_] = Result,
145     [Attributes|_]=Re#xmlElement.attributes,
146     ResultCode = Attributes#xmlAttribute.value,
147     ?assertMatch(ResultCode,Code).
148 
 

 

其它 操作 xmerl_xpath:string("//myelement[. = 'x']/text()",

ParsedDocumentRootElement).  

 

xmerl_xpath:string("//myelement[@myattribute='red']“, 

            ParsedDocumentRootElement). 

 

merl_xpath:string("//myelement[@myattribute='red' and . = 'y']“, 
            ParsedDocumentRootElement). 

 

 

参考 http://www.iteye.com/topic/610820

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值