读取和处理XML文件所需的帮助 [英] help needed in reading and processing XML file
问题描述
VS2015
我正在编写crm工作流程以从xml文件导入数据
I am writing a crm workflow to import data from an xml file
我需要做的是读取xml文件并提取2条数据,然后从现有xml文件中为每个供应商xml文件创建一个
What I need to do is read the xml file and extract 2 pieces of data and create a for each supplier xml file from the existing xml file
原始XML
<?xml version ="1.0" encoding ="UTF-8"?>
<汇款>
<汇款>
< supplier vendorref ="SUP01" Suppliername ="COMPANY 1" />
< faxnumber Faxnumber ="12345 678679" />
< remittancedate RemittanceDate ="2017年5月1日" paymentdate ="2017年11月1日00:00"; />
< address address-1 ="House 1".地址2 =街道1",地址3 =街道2",地址4 =县1" address-5 =邮政编码1" />
< remittance remitlinedate =" 10-10-2016" remitlineourref ="00003258" remitlinedoctype ="INVOICE" remitlineyourref =发票1", itemvalue ="100.00" />
< remittance remitlinedate =" 09-11-2016" remitlineourref ="00002365" remitlinedoctype ="INVOICE" remitlineyourref =发票49", itemvalue ="505.27" />
</汇款>
<汇款>
< supplier vendorref ="SUP03" Suppliername ="COMPANY 2" />
< faxnumber传真号码="12345 987987" />
< remittancedate RemittanceDate ="2017年5月1日" paymentdate ="2017年11月1日00:00"; />
< address address-1 ="House 2".地址2 =街道2",地址3 =街道3",地址4 =县4" address-5 =邮政编码7", />
< remittance remitlinedate =" 01/01/2017" remitlineourref ="00005555" remitlinedoctype ="INVOICE" remitlineyourref =发票8", itemvalue ="1.00" />
</汇款>
</汇款>
<?xml version="1.0" encoding="UTF-8"?>
<Remittances>
<Remittance>
<supplier supplierref="SUP01" suppliername="COMPANY 1" />
<faxnumber faxnumber="12345 678679" />
<remittancedate RemittanceDate="05/01/2017" paymentdate="11/01/2017 00:00" />
<address address-1="House 1" address-2="Street 1" address-3="street 2" address-4="county 1" address-5="postcode 1" />
<remittance remitlinedate="10-10-2016" remitlineourref="00003258" remitlinedoctype="INVOICE" remitlineyourref="Invoice 1" itemvalue="100.00" />
<remittance remitlinedate="09-11-2016" remitlineourref="00002365" remitlinedoctype="INVOICE" remitlineyourref="Invoice 49" itemvalue="505.27" />
</Remittance>
<Remittance>
<supplier supplierref="SUP03" suppliername="COMPANY 2" />
<faxnumber faxnumber="12345 987987" />
<remittancedate RemittanceDate="05/01/2017" paymentdate="11/01/2017 00:00" />
<address address-1="House 2" address-2="Street 2" address-3="street 3" address-4="county 4" address-5="postcode 7" />
<remittance remitlinedate="01/01/2017" remitlineourref="00005555" remitlinedoctype="INVOICE" remitlineyourref="Invoice 8" itemvalue="1.00" />
</Remittance>
</Remittances>
我想要去的是
将SupplierRef声明为String = string.empty
declare SupplierRef as String = string.empty
将SupplierName声明为String = string.empty
declare SupplierName as String = string.empty
将xmlFile声明为string = string.empty
declare xmlFile as string = string.empty
在do while循环中
on a do while loop
(第一供应商)
SupplierRef ="SUP01"
SupplierRef = "SUP01"
SupplierName = "COMPANY 1"
SupplierName = "COMPANY 1"
xmlFile = <?xml version ='1.0' encoding ="UTF-8"?>
<汇款>
<汇款>
< supplier vendorref ="SUP01" Suppliername ="COMPANY 1" />
< faxnumber Faxnumber ="12345 678679" />
< remittancedate RemittanceDate ="2017年5月1日" paymentdate ="2017年11月1日00:00"; />
< address address-1 ="House 1".地址2 =街道1",地址3 =街道2",地址4 =县1" address-5 =邮政编码1" />
< remittance remitlinedate ="2016年10月10日" remitlineourref ="00003258" remitlinedoctype ="INVOICE" remitlineyourref =发票1", itemvalue ="100.00" />
< remittance remitlinedate =" 09-11-2016" remitlineourref ="00002365" remitlinedoctype ="INVOICE"; remitlineyourref =发票49", itemvalue ="505.27" />
</汇款>
</汇款> "
xmlFile = "<?xml version="1.0" encoding="UTF-8"?>
<Remittances>
<Remittance>
<supplier supplierref="SUP01" suppliername="COMPANY 1" />
<faxnumber faxnumber="12345 678679" />
<remittancedate RemittanceDate="05/01/2017" paymentdate="11/01/2017 00:00" />
<address address-1="House 1" address-2="Street 1" address-3="street 2" address-4="county 1" address-5="postcode 1" />
<remittance remitlinedate="10-10-2016" remitlineourref="00003258" remitlinedoctype="INVOICE" remitlineyourref="Invoice 1" itemvalue="100.00" />
<remittance remitlinedate="09-11-2016" remitlineourref="00002365" remitlinedoctype="INVOICE" remitlineyourref="Invoice 49" itemvalue="505.27" />
</Remittance>
</Remittances> "
(第二个供应商)
SupplierRef ="SUP03"
SupplierRef = "SUP03"
SupplierName = "COMPANY 2"
SupplierName = "COMPANY 2"
xmlFile =<?xml version =" 1.0"encoding ="UTF-8"?>
<汇款>
<汇款>
< supplier vendorref ="SUP03" Suppliername ="COMPANY 2" />
< faxnumber传真号码="12345 987987" />
< remittancedate RemittanceDate ="2017年5月1日" paymentdate ="2017年11月1日00:00"; />
< address address-1 ="House 2".地址2 =街道2",地址3 =街道3",地址4 =县4" address-5 =邮政编码7", />
< remittance remitlinedate =" 01/01/2017" remitlineourref ="00005555" remitlinedoctype ="INVOICE" remitlineyourref =发票8", itemvalue ="1.00" />
</汇款>
</汇款>"
xmlFile = "<?xml version="1.0" encoding="UTF-8"?>
<Remittances>
<Remittance>
<supplier supplierref="SUP03" suppliername="COMPANY 2" />
<faxnumber faxnumber="12345 987987" />
<remittancedate RemittanceDate="05/01/2017" paymentdate="11/01/2017 00:00" />
<address address-1="House 2" address-2="Street 2" address-3="street 3" address-4="county 4" address-5="postcode 7" />
<remittance remitlinedate="01/01/2017" remitlineourref="00005555" remitlinedoctype="INVOICE" remitlineyourref="Invoice 8" itemvalue="1.00" />
</Remittance>
</Remittances>"
等
任何帮助或建议都将非常有帮助
any help or advice would be very helpful
不要问我..我不知道
推荐答案
Pete,
查看以下内容是否可以帮助您入门.它使用LINQ-To-XML.
See if the following will help you get started. It uses LINQ-To-XML.
我将XML放在桌面上的文件中
I put the XML in a file on my desktop:
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Class Supplier
Public Property Ref As String
Public Property Name As String
End Class
Private Sub Form1_Load(sender As System.Object, _
e As System.EventArgs) _
Handles MyBase.Load
Dim supplierList As New List(Of Supplier)
Dim desktop As String = _
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim xPath As String = _
IO.Path.Combine(desktop, "Example.xml")
If IO.File.Exists(xPath) Then
Dim xDoc As XElement = XElement.Load(xPath)
For Each supplierInfo As XElement In xDoc...<supplier>
supplierList.Add(New Supplier _
With {.Name = supplierInfo.@supplierref, _
.Ref = supplierInfo.@suppliername})
Next
End If
Stop
' Hover your mouse over "supplierList" and
' you'll see the instances created from the
' XML file.
End Sub
End Class
这篇关于读取和处理XML文件所需的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!