初次使用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

 

你可能感兴趣的:(xml,UP)