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

  • 相关阅读:
    进程通信
    python模块成像库pillow
    python模块IO
    python模块StringIO和BytesIO
    DJango重写用户模型
    DJango模型Meta选项详解
    DJango中事务的使用
    批量删除文件
    批量修改文件名字或后缀
    自定义中间件实现插拔设计
  • 原文地址:https://www.cnblogs.com/lbnnbs/p/4784593.html
Copyright © 2011-2022 走看看