以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 帮我看看哪里错了? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=161555) |
||||||||
-- 作者:hongye -- 发布时间:2021/3/22 14:50:00 -- 帮我看看哪里错了? Dim sa1 As String = "A01" Dim fsc As String = "开票数据" Dim drU As DataRow drU = DataTables("表C").Find("[执行编号] = \'" & sa1 & "\' And [分类] = \'" & fsc & "\'") Dim dzml1 As String = drU("主文件夹目录") Dim dzml2 As String = drU("次文件夹目录") For Each f As String In FileSys.GetFiles(dzml2) If f.EndsWith(".log") 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("comment") For Each dr As object In ndlist 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 For i As Integer = 0 To ndList.count - 1 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 Next Dim ndList1 = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes For i As Integer = 0 To ndList.count - 1 Dim spmc As String = ndList1(i).Item("spmc").InnerText Dim ggxh As String = ndList1(i).Item("ggxh").InnerText Dim sl As String = ndList1(i).Item("sl").InnerText Dim se As String = ndList1(i).Item("se").InnerText Dim dw As String = ndList1(i).Item("dw").InnerText Dim spsl As String = ndList1(i).Item("spsl").InnerText Dim dj As String = ndList1(i).Item("dj").InnerText Dim je As String = ndList1(i).Item("je").InnerText Dim r As Row = Tables("表B").AddNew r("第一列") = fpdm r("第二列") = fphm r("第三列") = ghdwmc r("第四列") = spmc r("第五列") = ggxh r("第六列") = dw r("第七列") = spsl r("第八列") = dj r("第十列") = "str" Next Next End If Next
这个代码应该怎么写啊 [此贴子已经被作者于2021/3/22 14:51:03编辑过]
|
||||||||
-- 作者:有点蓝 -- 发布时间:2021/3/22 14:57:00 -- 里面有不属于xml内容的字符,要去掉才能作为xml解析 |
||||||||
-- 作者:hongye -- 发布时间:2021/3/22 14:59:00 -- 那有什么办法读取的时候去掉呢? |
||||||||
-- 作者:有点蓝 -- 发布时间:2021/3/22 15:01:00 -- 获取第一个<符号的位置:http://www.foxtable.com/webhelp/topics/0236.htm |
||||||||
-- 作者:hongye -- 发布时间:2021/3/22 18:18:00 -- ![]() ![]() 现在变这样了
|
||||||||
-- 作者:有点蓝 -- 发布时间:2021/3/22 20:34:00 -- 具体代码? |
||||||||
-- 作者:hongye -- 发布时间:2021/3/23 7:21:00 -- Dim sa1 As String = "A01" Dim fsc As String = "开票数据" Dim drU As DataRow drU = DataTables("表C").Find("[执行编号] = \'" & sa1 & "\' And [分类] = \'" & fsc & "\'") Dim dzml1 As String = drU("主文件夹目录") Dim dzml2 As String = drU("次文件夹目录") For Each f As String In FileSys.GetFiles(dzml2) If f.EndsWith(".log") Then Dim txt As String = FileSys.ReadAllText(f, Encoding.Default) Dim idx As Integer = txt.IndexOf("<?xml version") Dim s2 As String = txt.SubString(idx) Dim sx As String = "s2" MessageBox.Show(s2) Dim xmlDoc As New System.XML.XmlDocument xmlDoc.Loadxml(s2) MessageBox.Show("0") Dim ndList = xmlDoc.GetElementsByTagName("comment") For Each dr As object In ndlist 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 For i As Integer = 0 To ndList.count - 1 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 Next Dim ndList1 = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes For i As Integer = 0 To ndList.count - 1 Dim spmc As String = ndList1(i).Item("spmc").InnerText Dim ggxh As String = ndList1(i).Item("ggxh").InnerText Dim sl As String = ndList1(i).Item("sl").InnerText Dim se As String = ndList1(i).Item("se").InnerText Dim dw As String = ndList1(i).Item("dw").InnerText Dim spsl As String = ndList1(i).Item("spsl").InnerText Dim dj As String = ndList1(i).Item("dj").InnerText Dim je As String = ndList1(i).Item("je").InnerText Dim r As Row = Tables("表B").AddNew r("第一列") = fpdm r("第二列") = fphm r("第三列") = ghdwmc r("第四列") = spmc r("第五列") = ggxh r("第六列") = dw r("第七列") = spsl r("第八列") = dj r("第十列") = "str" Next Next End If Next
搞不来了,请大神帮忙改改吧 [此贴子已经被作者于2021/3/23 8:31:51编辑过]
|
||||||||
-- 作者:有点蓝 -- 发布时间:2021/3/23 9:19:00 -- 文件里面是N段XML而不是只有一个 Dim txt As String = FileSys.ReadAllText("d:\\问题\\_2020-12-19.log", Encoding.Default) Dim idx As Integer = txt.IndexOf("<?xml version") Dim idx2 As Integer = txt.IndexOf("</business>",idx) Do While idx > -1 And idx2 > -1 Dim s2 As String = txt.SubString(idx,idx2-idx+11) Output.Show(s2) Output.Show("-------------------------------") ‘对xml的处理 idx = txt.IndexOf("<?xml version",idx2) If idx > -1 idx2 = txt.IndexOf("</business>",idx) Else idx2=-1 End If Loop |
||||||||
-- 作者:hongye -- 发布时间:2021/3/23 9:57:00 -- Dim sa1 As String = "A01" Dim fsc As String = "开票数据" Dim drU As DataRow drU = DataTables("表C").Find("[执行编号] = \'" & sa1 & "\' And [分类] = \'" & fsc & "\'") Dim dzml1 As String = drU("主文件夹目录") Dim dzml2 As String = drU("次文件夹目录") For Each f As String In FileSys.GetFiles(dzml2) If f.EndsWith(".log") Then Dim txt As String = FileSys.ReadAllText(f, Encoding.Default) Dim idx As Integer = txt.IndexOf("<?xml version") Dim idx2 As Integer = txt.IndexOf("</business>",idx) Do While idx > -1 And idx2 > -1 Dim s2 As String = txt.SubString(idx,idx2-idx+11) idx = txt.IndexOf("<?xml version",idx2) If idx > -1 idx2 = txt.IndexOf("</business>",idx) Else idx2=-1 End If Dim xmlDoc As New System.XML.XmlDocument xmlDoc.Loadxml(s2) Dim ndList = xmlDoc.GetElementsByTagName("comment") For Each dr As object In ndlist 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 For i As Integer = 0 To ndList.count - 1 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 Next Dim ndList1 = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes For i As Integer = 0 To ndList.count - 1 Dim spmc As String = ndList1(i).Item("spmc").InnerText Dim ggxh As String = ndList1(i).Item("ggxh").InnerText Dim sl As String = ndList1(i).Item("sl").InnerText Dim se As String = ndList1(i).Item("se").InnerText Dim dw As String = ndList1(i).Item("dw").InnerText Dim spsl As String = ndList1(i).Item("spsl").InnerText Dim dj As String = ndList1(i).Item("dj").InnerText Dim je As String = ndList1(i).Item("je").InnerText Dim r As Row = Tables("表B").AddNew r("第一列") = fpdm r("第二列") = fphm r("第三列") = ghdwmc r("第四列") = spmc r("第五列") = ggxh r("第六列") = dw r("第七列") = spsl r("第八列") = dj r("第十列") = "str" Next Next Loop End If Next 错误是没有了,但是没有将数据写入表中,这是为什么?
|
||||||||
-- 作者:有点蓝 -- 发布时间:2021/3/23 10:02:00 -- 这个您要自己调试分析xml的节点 Dim ndList1 = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes msgbox(ndList.count ) For i As Integer = 0 To ndList.count - 1 Dim spmc As String = ndList1(i).Item("spmc").InnerText msgbox(spmc ) Dim ggxh As String = ndList1(i).Item("ggxh").InnerText msgbox(ggxh ) …… |