zoukankan      html  css  js  c++  java
  • 使用正则表达式读取简单的xml文件

    '<?xml version='1.0' encoding='GB2312'?>
    '<ntsc>
    '   <time>
    '       <year>2010</year>
    '       <month>10</month>
    '       <day>31</day>
    '       <Weekday></Weekday>
    '       <hour>11</hour>
    '       <minite>29</minite>
    '       <second>35</second>
    '       <Millisecond></Millisecond>
    '   </time>
    '</ntsc>

    Public Function GetXmlValue(ByVal sKey As String, ByVal sSrc As String) As String
       
        Dim regEx As RegExp ' 需要引用 Microsof VBScript Regular Expressions 5.5
        Dim m As Match ' 是一个对象,
        Dim ms As MatchCollection ' 是一个数组 property: count, item
        Dim sms As SubMatches ' 是一个数组
        Dim v As Object
       
        Set regEx = New RegExp ' 建立正则表达式。
       
        regEx.Pattern = "<" & sKey & ">(.*)</" & sKey & ">" ' 设置模式。
        regEx.IgnoreCase = True ' 设置是否区分字符大小写。
        regEx.Global = False ' 设置只返回第一个匹配的结果,因为也就只有一个。
        Set ms = regEx.Execute(sSrc) ' 执行搜索。
       
        GetXmlValue = ms(0).SubMatches(0)
    End Function

  • 相关阅读:
    南大《软件分析》课程笔记——Intermediate Representation
    leetcode刷题
    shiro550反序列化分析
    南大《软件分析》课程笔记——第一课
    再见2020
    S2-002漏洞分析
    编码&解码工具
    正码、反码和补码
    Java数据结构(二)
    Java数据集合
  • 原文地址:https://www.cnblogs.com/lbnnbs/p/4784593.html
Copyright © 2011-2022 走看看