Foxtable(狐表)用户栏目专家坐堂 → 关于XML的问题,初学,请发代码学习


  共有7616人关注过本帖树形打印复制链接

主题:关于XML的问题,初学,请发代码学习

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/10 10:21:00 [显示全部帖子]

参考代码

 


For Each f As String In FileSys.GetFiles("C:\Users\dv rrxaI600 007\Downloads\fa piao\Jskp")
    Dim txt As String = FileSys.ReadAllText(f, Encoding.utf8)
    Dim xmlDoc As New System.XML.XmlDocument
    xmlDoc.Loadxml(txt.Trim)
    Dim ndList  = xmlDoc.GetElementsByTagName("Sph")
    For Each dr As object In ndlist
        Dim ndr As Row = Tables("表A").addnew
        For Each n As System.XML.XmlNode In dr.childNodes
            output.show(n.Name & " = " & n.InnerText)
            If n.name = "Spmc" Then
                ndr("客户名称") = n.innertext
            End If
            If n.name = "sl" Then
                ndr("数量") = val(n.innertext)
            End If
        Next
    Next
Next


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/10 11:21:00 [显示全部帖子]

Dim str = "3100183130_19619734_0.xml"
Dim ary = str.split("_")
msgbox(ary(0))
msgbox(ary(1))

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/10 12:21:00 [显示全部帖子]

代码没问题,我测试没问题。

 

只要你路径没写错,就不可能有问题。

 

你弹出msgbox(dzml2)、msgbox(f)的值看看


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/11 12:51:00 [显示全部帖子]

这个

 

Dim ndr As Row = Tables("表b").addnew

 

改成

 

Dim ndr As dataRow = dataTables("表b").find("某列='" & dr("fpdm") & "'")

If ndr is Nothing then ndr = dataTables("表b").addnew


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/11 17:36:00 [显示全部帖子]

改成

 

Dim ndr As dataRow = dataTables("表b").find("某列='" & dr("fpdm").innertext & "'")

If ndr is Nothing then ndr = dataTables("表b").addnew


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/13 10:45:00 [显示全部帖子]

 

xml文件和你的程序,一起发上来测试。

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/13 11:29:00 [显示全部帖子]

Dim db3 As WinForm.DropDownBox = e.Form.Controls("DropBox3")
Dim dzml3 As String = db3.text '"C:\Users\dv rrxaI600 007\Downloads\foxtable项目\客户编码\"
For Each f As String In FileSys.GetFiles(dzml3)
    If f.EndsWith(".txt") Then
        Tables("表C").StopRedraw
        Dim strs As String = FileSys.ReadAllText(f,Encoding.Default)
        strs = strs.Replace(vblf,"")
        Dim rs() As String = strs.Split(vbcr)
        For i As Integer = 3 To rs.Length - 1
            Dim cs() As String = rs(i).replace("~~","~").Split("~")
            If cs.Length = 9 Then
                If DataTables("表c").Find("名称 = '" & cs(1) & "'and 税号 = '" & cs(3) & "'") Is Nothing Then
                    Dim dr As DataRow = DataTables("表C").Addnew()
                    dr("名称") = cs(1)
                    dr("税号") = cs(3)
                    dr("地址电话") = cs(4)
                    dr("银行账号") = cs(5)
                End If
            End If
        Next
        Tables("表C").ResumeRedraw
    End If
Next
For Each f As String In FileSys.GetFiles(dzml3)
    If f.EndsWith(".xml") Then
        Dim txt As String = FileSys.ReadAllText(f, Encoding.Default)
        Dim xmlDoc As New System.XML.XmlDocument
        xmlDoc.Loadxml(txt.Trim)
        Dim ndList  = xmlDoc.GetElementsByTagName("Row")
        For Each dr As object In ndlist
            If dr.Attributes("NSRSBH") IsNot Nothing Then
                Dim ndr As DataRow = DataTables("表C").find("名称 = '" & dr.Attributes("MC").value  & "' and 税号 = '" & dr.Attributes("NSRSBH").value  & "'")
                If ndr Is Nothing Then ndr = DataTables("表C").addnew
                ndr("名称") = dr.GetAttribute("MC")
                ndr("税号") = dr.GetAttribute("NSRSBH")
                ndr("地址电话") = dr.GetAttribute("DZ")
                ndr("银行账号")  = dr.GetAttribute("YHZH")
            End If
        Next
    End If
Next
DataTables("表c").DeleteFor("名称 Is Null   And 税号 Is Null   And 地址电话 Is Null  And 银行账号 Is Null ")

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/13 15:43:00 [显示全部帖子]

Dim ndrb1 As DataRow = DataTables("表c").find("税号 = '" &  ndr("纳税人识别号") & "'")
If ndrb1 IsNot Nothing Then
    ndr("客户名称") = ndrb1("名称")
    ndr("地址电话") = ndrb1("地址电话")
    ndr("开户银行及账号") = ndrb1("银行账号")   
End If


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/13 17:07:00 [显示全部帖子]

报错是因为你路径没有写对导致的。我用下面代码测试没问题

 

'Dim db4 As WinForm.DropDownBox = e.Form.Controls("DropBox4")
'Dim db5 As WinForm.DropDownBox = e.Form.Controls("DropBox5")
Dim dzml4 As String = "C:\Users\dv rrxaI600 007\Downloads\signlog\SignLog\20170606" 'db4.text
'Dim dzml5 As String = db5.text
If dzml4 IsNot Nothing Then
    Tables("表A").StopRedraw
    For Each f As String In FileSys.GetFiles(dzml4)
        If f.EndsWith("_verifysign.log") Then
            If DataTables("表B").Find("文件名 = '" & f & "'" ) Is Nothing Then
                Dim txt As String = FileSys.ReadAllText(f, Encoding.Default)
                Dim idx As Integer = txt.IndexOf("</business>")
               
                Dim s1 As String = txt.SubString(0, idx+11)
                Dim s2 As String = txt.SubString(idx+12)
                Dim xmlDoc As New System.XML.XmlDocument
                xmlDoc.Loadxml(s1)
               
                Dim ndList  = xmlDoc.GetElementsByTagName("input")
                Dim kprq As String
                Dim fpdm As String
                Dim fphm As String
                Dim ghdwmc As String
                Dim ghdwdzdh As String
                Dim ghdwsbh As String
                Dim ghdwyhzh As String
                Dim hjje As String
                Dim hjse As String
                Dim jshj As String
                Dim bz As String
                Dim fpzt As String
                For i As Integer = 0 To ndList.count - 1
                    If ndList(i).Item("kprq") IsNot Nothing Then kprq = ndList(i).Item("kprq").InnerText
                    If ndList(i).Item("fpdm") IsNot Nothing Then fpdm = ndList(i).Item("fpdm").InnerText
                    If ndList(i).Item("fphm") IsNot Nothing Then fphm = ndList(i).Item("fphm").InnerText
                    If ndList(i).Item("ghdwmc") IsNot Nothing Then ghdwmc = ndList(i).Item("ghdwmc").InnerText
                    If ndList(i).Item("ghdwdzdh") IsNot Nothing Then ghdwdzdh = ndList(i).Item("ghdwdzdh").InnerText
                    If ndList(i).Item("ghdwsbh") IsNot Nothing Then ghdwsbh = ndList(i).Item("ghdwsbh").InnerText
                    If ndList(i).Item("ghdwyhzh") IsNot Nothing Then ghdwyhzh = ndList(i).Item("ghdwyhzh").InnerText
                    If ndList(i).Item("hjje") IsNot Nothing Then hjje = ndList(i).Item("hjje").InnerText
                    If ndList(i).Item("hjse") IsNot Nothing Then hjse = ndList(i).Item("hjse").InnerText
                    If ndList(i).Item("jshj") IsNot Nothing Then jshj = ndList(i).Item("jshj").InnerText
                    If ndList(i).Item("bz") IsNot Nothing Then bz = ndList(i).Item("bz").InnerText
                    If ndList(i).Item("fpzt") IsNot Nothing Then fpzt = ndList(i).Item("fpzt").InnerText
                Next
                If fphm <> Nothing Then
                    Dim ndr As DataRow = DataTables("表b").addnew
                    ndr("开piao日期") = kprq.SubString(0,4) + "-" + kprq.SubString(4,2) + "-" + kprq.SubString(6,2)
                    ndr("fa piao代码") = fpdm
                    ndr("fa piao号码") = fphm
                    ndr("客户名称") =ghdwmc
                    ndr("地址电话") =ghdwdzdh
                    ndr("纳税人识别号") = ghdwsbh
                    ndr("开户银行及账号") = ghdwyhzh
                    ndr("合计金额") = hjje
                    ndr("合计税额") = hjse
                    ndr("价税合计") = jshj
                    ndr("备注") = bz
                    ndr("fa piao状态") = fpzt
                    ndr("文件名") = f
                    ndList = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes
                    For i As Integer = 0 To ndList.count - 1
                        Dim spmc As String = ndList(i).Item("spmc").InnerText
                        Dim ggxh As String = ndList(i).Item("ggxh").InnerText
                        Dim sl As String = ndList(i).Item("sl").InnerText
                        Dim se As String = ndList(i).Item("se").InnerText
                        Dim dw As String = ndList(i).Item("dw").InnerText
                        Dim spsl As String = ndList(i).Item("spsl").InnerText
                        Dim dj As String = ndList(i).Item("dj").InnerText
                        Dim je As String = ndList(i).Item("je").InnerText
                        Dim r As Row = Tables("表A").AddNew
                        r("fa piao代码") = fpdm
                        r("fa piao号码") = fphm
                        r("客户名称") = ghdwmc
                        r("货物或服务名称") = spmc
                        r("规格") = ggxh
                        r("单位") = dw
                        r("数量") = val(spsl)
                        r("单价") = dj
                        r("税率") = sl
                        r("税额") = se
                        r("金额") = je
                        r("fa piao状态") = fpzt
                    Next
                End If
            End If
        End If
    Next
    Tables("表A").ResumeRedraw
    DataTables("表b").DeleteFor("fa piao状态 = '2'")
    For Each s As String In DataTables("表A").GetValues("fa piao号码", "fa piao状态 = '3'")
        DataTables("表A").DeleteFor("fa piao号码 = '" & s & "' and fa piao状态 = '0'")
    Next
    For Each s1 As String In DataTables("表b").GetValues("fa piao号码", "fa piao状态 = '3'")
        DataTables("表b").DeleteFor("fa piao号码 = '" & s1 & "' and fa piao状态 = '0'")
    Next
End If


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/13 17:33:00 [显示全部帖子]

Dim dzml4 As String = "C:\Users\dv rrxaI600 007\Downloads\signlog\SignLog\"
If dzml4 IsNot Nothing Then
    Tables("表A").StopRedraw
    For Each dir As String In FileSys.GetDirectories(dzml4)
        For Each f As String In FileSys.GetFiles(dir)
            If f.EndsWith("_verifysign.log") Then
                Dim str = f.SubString(f.Length - 38)
                If DataTables("表B").Find("文件名 = '" & str & "'" ) Is Nothing Then
                    Dim txt As String = FileSys.ReadAllText(f, Encoding.Default)
                    Dim idx As Integer = txt.IndexOf("</business>")
                   
                    Dim s1 As String = txt.SubString(0, idx+11)
                    Dim s2 As String = txt.SubString(idx+12)
                    Dim xmlDoc As New System.XML.XmlDocument
                    xmlDoc.Loadxml(s1)
                   
                    Dim ndList  = xmlDoc.GetElementsByTagName("input")
                    Dim kprq As String
                    Dim fpdm As String
                    Dim fphm As String
                    Dim ghdwmc As String
                    Dim ghdwdzdh As String
                    Dim ghdwsbh As String
                    Dim ghdwyhzh As String
                    Dim hjje As String
                    Dim hjse As String
                    Dim jshj As String
                    Dim bz As String
                    Dim fpzt As String
                    For i As Integer = 0 To ndList.count - 1
                        If ndList(i).Item("kprq") IsNot Nothing Then kprq = ndList(i).Item("kprq").InnerText
                        If ndList(i).Item("fpdm") IsNot Nothing Then fpdm = ndList(i).Item("fpdm").InnerText
                        If ndList(i).Item("fphm") IsNot Nothing Then fphm = ndList(i).Item("fphm").InnerText
                        If ndList(i).Item("ghdwmc") IsNot Nothing Then ghdwmc = ndList(i).Item("ghdwmc").InnerText
                        If ndList(i).Item("ghdwdzdh") IsNot Nothing Then ghdwdzdh = ndList(i).Item("ghdwdzdh").InnerText
                        If ndList(i).Item("ghdwsbh") IsNot Nothing Then ghdwsbh = ndList(i).Item("ghdwsbh").InnerText
                        If ndList(i).Item("ghdwyhzh") IsNot Nothing Then ghdwyhzh = ndList(i).Item("ghdwyhzh").InnerText
                        If ndList(i).Item("hjje") IsNot Nothing Then hjje = ndList(i).Item("hjje").InnerText
                        If ndList(i).Item("hjse") IsNot Nothing Then hjse = ndList(i).Item("hjse").InnerText
                        If ndList(i).Item("jshj") IsNot Nothing Then jshj = ndList(i).Item("jshj").InnerText
                        If ndList(i).Item("bz") IsNot Nothing Then bz = ndList(i).Item("bz").InnerText
                        If ndList(i).Item("fpzt") IsNot Nothing Then fpzt = ndList(i).Item("fpzt").InnerText
                    Next
                    If fphm <> Nothing Then
                        Dim ndr As DataRow = DataTables("表b").addnew
                        ndr("开piao日期") = kprq.SubString(0,4) + "-" + kprq.SubString(4,2) + "-" + kprq.SubString(6,2)
                        ndr("fa piao代码") = fpdm
                        ndr("fa piao号码") = fphm
                        ndr("客户名称") =ghdwmc
                        ndr("地址电话") =ghdwdzdh
                        ndr("纳税人识别号") = ghdwsbh
                        ndr("开户银行及账号") = ghdwyhzh
                        ndr("合计金额") = hjje
                        ndr("合计税额") = hjse
                        ndr("价税合计") = jshj
                        ndr("备注") = bz
                        ndr("fa piao状态") = fpzt
                       
                        ndr("文件名") = str
                        ndList = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes
                        For i As Integer = 0 To ndList.count - 1
                            Dim spmc As String = ndList(i).Item("spmc").InnerText
                            Dim ggxh As String = ndList(i).Item("ggxh").InnerText
                            Dim sl As String = ndList(i).Item("sl").InnerText
                            Dim se As String = ndList(i).Item("se").InnerText
                            Dim dw As String = ndList(i).Item("dw").InnerText
                            Dim spsl As String = ndList(i).Item("spsl").InnerText
                            Dim dj As String = ndList(i).Item("dj").InnerText
                            Dim je As String = ndList(i).Item("je").InnerText
                            Dim r As Row = Tables("表A").AddNew
                            r("fa piao代码") = fpdm
                            r("fa piao号码") = fphm
                            r("客户名称") = ghdwmc
                            r("货物或服务名称") = spmc
                            r("规格") = ggxh
                            r("单位") = dw
                            r("数量") = val(spsl)
                            r("单价") = dj
                            r("税率") = sl
                            r("税额") = se
                            r("金额") = je
                            r("fa piao状态") = fpzt
                            ndr("文件名") = str
                        Next
                    End If
                End If
            End If
        Next
    Next
    Tables("表A").ResumeRedraw
    DataTables("表b").DeleteFor("fa piao状态 = '2'")
    For Each s As String In DataTables("表A").GetValues("fa piao号码", "fa piao状态 = '3'")
        DataTables("表A").DeleteFor("fa piao号码 = '" & s & "' and fa piao状态 = '0'")
    Next
    For Each s1 As String In DataTables("表b").GetValues("fa piao号码", "fa piao状态 = '3'")
        DataTables("表b").DeleteFor("fa piao号码 = '" & s1 & "' and fa piao状态 = '0'")
    Next
End If

 回到顶部
总数 12 1 2 下一页