以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关于XML的问题,初学,请发代码学习  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=131934)

--  作者:hongyefor
--  发布时间:2019/3/9 15:41:00
--  关于XML的问题,初学,请发代码学习

我有一个文件名为3100183130_19619745_0.xml,里面内容为

 

<?xml version="1.0" encoding="utf-8" ?>
<Kp>
    <Version />
    <Fpxx>
        <Zsl>1</Zsl>
        <Fpsj>
            <Fp>
                <Djh>1</Djh>
                <Gfmc />
                <Gfsh />
                <Gfyhzh />
                <Gfdzdh />
                <Bz />
                <Fhr></Fhr>
                <Skr></Skr>
                <Spbmbbh>30.0</Spbmbbh>
                <Hsbz>1</Hsbz>
                <Spxx>
                    <Sph>
                        <Xh>1</Xh>
                        <Spmc>夹克</Spmc>
                        <Ggxh>V191MN504402</Ggxh>
                        <Jldw>件</Jldw>
                        <Spbm>1040201120000000000</Spbm>
                        <Qyspbm />
                        <Syyhzcbz />
                        <Lslbz />
                        <Yhzcsm />
                        <Dj>168.10</Dj>
                        <Sl>77.0</Sl>
                        <Je>12943.97</Je>
                        <Slv>0.16</Slv>
                        <Kce>2071.03</Kce>
                    </Sph>
                    <Sph>
                        <Xh>2</Xh>
                        <Spmc>夹克</Spmc>
                        <Ggxh>V191MN504303</Ggxh>
                        <Jldw>件</Jldw>
                        <Spbm>1040201120000000000</Spbm>
                        <Qyspbm />
                        <Syyhzcbz />
                        <Lslbz />
                        <Yhzcsm />
                        <Dj>195.69</Dj>
                        <Sl>274.0</Sl>
                        <Je>53618.97</Je>
                        <Slv>0.16</Slv>
                        <Kce>8579.03</Kce>
                    </Sph>
                    <Sph>
                        <Xh>3</Xh>
                        <Spmc>夹克</Spmc>
                        <Ggxh>V191MN503903</Ggxh>
                        <Jldw>件</Jldw>
                        <Spbm>1040201120000000000</Spbm>
                        <Qyspbm />
                        <Syyhzcbz />
                        <Lslbz />
                        <Yhzcsm />
                        <Dj>232.76</Dj>
                        <Sl>123.0</Sl>
                        <Je>28629.31</Je>
                        <Slv>0.16</Slv>
                        <Kce>4580.69</Kce>
                    </Sph>
                </Spxx>
            </Fp>
        </Fpsj>
    </Fpxx>
</Kp>

我现在需要将该文件导入表A并将上面文件名3100183130_19619745_0的3100183130和19619745分别填入表A的代码列和编号列

<Xh>*</Xh>代表对应代码列和编号列的行数(不必导入) ,  <Spmc>**</Spmc>对应产品名称  ,  <Ggxh>*********</Ggxh>对应产品编号  ,  <Jldw>**</Jldw>对应产品的单位  ,  <Dj>****</Dj>对应单价 ,  <Sl>***</Sl>对应数量  ,  <Je>*****</Je>对应金额   ,   <Slv>***</Slv>对应税率   ,  <Kce>*****</Kce>对应税额 

以上如果有4个产品则将分别导入4行数据

如果该文件夹里有20个**********_*******_*则全部导入到表A

 

接下来还有一个XML文件

<?xml version="1.0" encoding="GBK"?>
<taxML cnName="增值税发票开具明细" xmlns="http://www.chinatax.gov.cn/dataspec/" name="slSbbtjZzsfpkjmxRequest" version="SW5001-2006" xsi:type="slSbbtjZzsfpkjmxRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <sbbZzsfpkjmx>
    <head>
      <publicHead>
        <nsrsbh>9131011656******N</nsrsbh>
        <nsrmc>上海公司</nsrmc>
        <tbrq>20190301</tbrq>
        <sssq>
          <rqQ>20190101</rqQ>
          <rqZ>20190331</rqZ>
        </sssq>
      </publicHead>
    </head>
    <body>
      <zyfpkjmx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619728</fphm>
          <kprq>20190112 13:23:04</kprq>
          <gmfnsrsbh>9131010758524048XB</gmfnsrsbh>
          <je>91120.69</je>
          <se>14579.31</se>
          <zfbz>N</zfbz>
          <xh>1</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619729</fphm>
          <kprq>20190112 13:40:57</kprq>
          <gmfnsrsbh>9131010758524048XB</gmfnsrsbh>
          <je>10224.14</je>
          <se>1635.86</se>
          <zfbz>N</zfbz>
          <xh>2</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619730</fphm>
          <kprq>20190112 13:44:35</kprq>
          <gmfnsrsbh>9131010758524048XB</gmfnsrsbh>
          <je>43943.97</je>
          <se>7031.03</se>
          <zfbz>N</zfbz>
          <xh>3</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619731</fphm>
          <kprq>20190112 13:48:52</kprq>
          <gmfnsrsbh>9131010758524048XB</gmfnsrsbh>
          <je>49645.19</je>
          <se>7943.23</se>
          <zfbz>N</zfbz>
          <xh>4</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619732</fphm>
          <kprq>20190112 13:56:46</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>99967.24</je>
          <se>15994.76</se>
          <zfbz>N</zfbz>
          <xh>5</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619733</fphm>
          <kprq>20190112 14:01:29</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>99853.45</je>
          <se>15976.55</se>
          <zfbz>N</zfbz>
          <xh>6</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619734</fphm>
          <kprq>20190112 14:04:37</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>99995.69</je>
          <se>15999.31</se>
          <zfbz>N</zfbz>
          <xh>7</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619735</fphm>
          <kprq>20190112 14:07:57</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>99894.83</je>
          <se>15983.17</se>
          <zfbz>Y</zfbz>
          <xh>8</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619736</fphm>
          <kprq>20190112 14:15:39</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>82768.11</je>
          <se>13242.89</se>
          <zfbz>Y</zfbz>
          <xh>9</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619737</fphm>
          <kprq>20190112 14:23:46</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>62159.48</je>
          <se>9945.52</se>
          <zfbz>N</zfbz>
          <xh>10</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619738</fphm>
          <kprq>20190112 14:24:31</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>49073.28</je>
          <se>7851.72</se>
          <zfbz>N</zfbz>
          <xh>11</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619739</fphm>
          <kprq>20190112 14:45:42</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>99894.83</je>
          <se>15983.17</se>
          <zfbz>N</zfbz>
          <xh>12</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619740</fphm>
          <kprq>20190112 14:49:20</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>82768.11</je>
          <se>13242.89</se>
          <zfbz>N</zfbz>
          <xh>13</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619741</fphm>
          <kprq>20190113 10:58:54</kprq>
          <gmfnsrsbh>9131010758524048XB</gmfnsrsbh>
          <je>32745.00</je>
          <se>5239.20</se>
          <zfbz>N</zfbz>
          <xh>14</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619742</fphm>
          <kprq>20190113 11:00:22</kprq>
          <gmfnsrsbh>9131010758524048XB</gmfnsrsbh>
          <je>23737.07</je>
          <se>3797.93</se>
          <zfbz>N</zfbz>
          <xh>15</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619743</fphm>
          <kprq>20190121 18:02:38</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>60600.00</je>
          <se>9696.00</se>
          <zfbz>N</zfbz>
          <xh>16</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619744</fphm>
          <kprq>20190121 18:05:04</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>99181.03</je>
          <se>15868.97</se>
          <zfbz>N</zfbz>
          <xh>17</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619745</fphm>
          <kprq>20190121 18:10:46</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>95192.25</je>
          <se>15230.75</se>
          <zfbz>N</zfbz>
          <xh>18</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619746</fphm>
          <kprq>20190121 18:11:53</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>86120.69</je>
          <se>13779.31</se>
          <zfbz>N</zfbz>
          <xh>19</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619747</fphm>
          <kprq>20190121 18:14:47</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>51537.93</je>
          <se>8246.07</se>
          <zfbz>Y</zfbz>
          <xh>20</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619748</fphm>
          <kprq>20190121 18:15:28</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>87856.03</je>
          <se>14056.97</se>
          <zfbz>Y</zfbz>
          <xh>21</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619749</fphm>
          <kprq>20190121 18:17:46</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>87856.03</je>
          <se>14056.97</se>
          <zfbz>N</zfbz>
          <xh>22</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100183130</fpdm>
          <fphm>19619750</fphm>
          <kprq>20190121 18:18:55</kprq>
          <gmfnsrsbh>913101103511274843</gmfnsrsbh>
          <je>51537.93</je>
          <se>8246.07</se>
          <zfbz>N</zfbz>
          <xh>23</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100184130</fpdm>
          <fphm>04985051</fphm>
          <kprq>20190219 15:56:21</kprq>
          <gmfnsrsbh>91310115630575335X</gmfnsrsbh>
          <je>21000.00</je>
          <se>3360.00</se>
          <zfbz>N</zfbz>
          <xh>24</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100184130</fpdm>
          <fphm>04985052</fphm>
          <kprq>20190220 12:11:01</kprq>
          <gmfnsrsbh>91320585079926788Y</gmfnsrsbh>
          <je>75387.93</je>
          <se>12062.07</se>
          <zfbz>N</zfbz>
          <xh>25</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100184130</fpdm>
          <fphm>04985053</fphm>
          <kprq>20190220 12:11:17</kprq>
          <gmfnsrsbh>91320585079926788Y</gmfnsrsbh>
          <je>75387.93</je>
          <se>12062.07</se>
          <zfbz>N</zfbz>
          <xh>26</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100184130</fpdm>
          <fphm>04985054</fphm>
          <kprq>20190220 12:11:32</kprq>
          <gmfnsrsbh>91320585079926788Y</gmfnsrsbh>
          <je>75387.93</je>
          <se>12062.07</se>
          <zfbz>N</zfbz>
          <xh>27</xh>
        </mxxx>
        <mxxx>
          <fpdm>3100184130</fpdm>
          <fphm>04985055</fphm>
          <kprq>20190225 17:15:59</kprq>
          <gmfnsrsbh>91320585079926788Y</gmfnsrsbh>
          <je>93606.90</je>
          <se>14977.10</se>
          <zfbz>N</zfbz>
          <xh>28</xh>
        </mxxx>
      </zyfpkjmx>
      <zyfpkjhjxx>
        <zyfpkjhjs>28</zyfpkjhjs>
        <zzszyfphjJe>1988443.66</zzszyfphjJe>
        <zzszyfphjSe>318150.96</zzszyfphjSe>
      </zyfpkjhjxx>
      <ptfpkjmx />
      <ptfpkjhjxx>
        <ptfpkjhjs>0</ptfpkjhjs>
        <ptfpkjhjJe>0</ptfpkjhjJe>
        <ptfpkjhjSe>0</ptfpkjhjSe>
      </ptfpkjhjxx>
    </body>
  </sbbZzsfpkjmx>
</taxML>

 

将对应的

          <fpdm>***</fpdm>代码列
          <fphm>***</fphm>编号列

          <kprq>******</kprq>日期
          <gmfnsrsbh>*****</gmfnsrsbh>客户代码
          <je>*****</je>总金额
          <se>*****</se>税额
          <zfbz>N</zfbz> 状态
分别填入表B对应的列

 

请问这个代码怎么写

 

 

<?

--  作者:hongyefor
--  发布时间:2019/3/9 15:44:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:发票.rar


--  作者:有点蓝
--  发布时间:2019/3/9 16:21:00
--  
参考:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=130061&skin=0
--  作者:hongyefor
--  发布时间:2019/3/9 16:30:00
--  
看不懂图片点击可在新窗口打开查看
--  作者:hongyefor
--  发布时间:2019/3/9 16:48:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目121.foxdb


--  作者:有点蓝
--  发布时间:2019/3/9 17:22:00
--  
Dim txt As String = FileSys.ReadAllText("D:\\问题\\发票\\Jskp\\3100183130_19619728_0.xml", Encoding.utf8)
Dim xmlDoc As New System.XML.XmlDocument
xmlDoc.Loadxml(txt.Trim)
Dim ndList  = xmlDoc.GetElementsByTagName("Djh")
output.show(ndlist(0).InnerText)
ndList  = xmlDoc.GetElementsByTagName("Spmc")
output.show(ndlist(0).InnerText)

--  作者:hongyefor
--  发布时间:2019/3/9 21:10:00
--  

For Each dir As String In FileSys.GetDirectories("I:\\发票\\Jskp")
    For Each f As String In FileSys.GetFiles(dir)
        Dim txt As String = FileSys.ReadAllText(f, Encoding.utf8)
        Dim xmlDoc As New System.XML.XmlDocument
        xmlDoc.Loadxml(txt.Trim)
        Dim ndList  = xmlDoc.GetElementsByTagName("Djh")
        output.show(ndlist(0).InnerText)
        ndList  = xmlDoc.GetElementsByTagName("Spmc")
        output.show(ndlist(0).InnerText)
    Next
Next

为什么没有反应,最好能否帮我在项目里写一下代码


--  作者:hongye
--  发布时间:2019/3/9 23:55:00
--  

帮我改改吧,实在不会了

 

 


 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目121.rar

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:发票.rar


--  作者:有点甜
--  发布时间:2019/3/10 10:21:00
--  

参考代码

 


For Each f As String In FileSys.GetFiles("C:\\Users\\dv rrxaI600 007\\Downloads\\发票\\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


--  作者:hongye
--  发布时间:2019/3/10 11:08:00
--  
如何提取文件名部分字符串的合集呢
比如
我要提取\\发票\\Jskp中
3100183130_19619734_0.xml
前面一部份3100183130 和 19619734