自定义函数: XML_Get ( InXML ; InElement ; InOccurrence ) 2020年5月18日 • XML 函数功能描述 来源: 作者: 作者原述: 猫壹佰描述: 获取XML键值 测试文档下载: 调用范例 XML_Get ( "<E1>A</E1><E2>B</E2><E1>C</E1>" ; "E2" ; 1 ) 返回结果 B 函数内容 Let([ ElementStart = Position( InXML ; "<" & InElement & ">" ; 1 ; InOccurrence ) ; ElementEnd = Position( InXML ; "</" & InElement & ">" ; 1 ; InOccurrence ) ; ValueStart = ElementStart + Length( InElement ) + 2 ; ElementValue = Middle( InXML ; ValueStart ; ElementEnd - ValueStart ) ; ElementValue = Trim( Substitute( ElementValue ; [ "¶" ; "" ] ; [ Char(9) ; "" ] ) ) ]; Case( ElementStart = 0; "Empty" ; // no matching element ElementEnd < ElementStart; "Empty" ; // xml format error IsEmpty( ElementValue ); "Empty" ; // element found, but no data ElementValue ) ) /* Return the text between the Element tags, for the given occurrence. If $XML = <E1>A</E1><E2>B</E2><E1>C</E1> then XML_Get( $XML ; "E1" ; 1 ) returns "A" XML_Get( $XML ; "E1" ; 2 ) returns "C" XML_Get( $XML ; "E3" ; 1 ) returns "Empty" There is no xml-path traversal, this is just simple matching. Returns "Empty" for missing, empty or if xml is misformatted; If you need to distinguish, then change results of error tests. P.S. This was inspired by Andy Knasinski's ExtractData() - I just reworked the concept into my way of thinking. */ 复制函数内容 当前页面使用FileMaker生成发布, 更新于2021年3月15日0时50分10秒 ← 较旧的文章 较新的文章 →