读取XML文件到表 [英] Read XML file to table

查看:80
本文介绍了读取XML文件到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我是xml的新手.所以我需要帮助使程序读取xml文件.

例如:

Hi, everybody!

I''m newcomer in xml. so i need help make program read xml file.

example:

<interaction channelVariable="Seller2CreditCardC" name="creditCardCheck" operation="creditCardCheck" >
			<participate toRole="CreditCardRole" relationshipType="SellerCreditCheck" fromRole="SellerRole"/>
			<exchange action="request" name="creditCardCheck" informationType="creditCardCheckType">
				<send variable="cdl:getVariable(creditCardValidity)"/>
				<receive variable="cdl:getVariable(creditCardValidity)"/>
			</exchange>
		</interaction>
		
		<interaction channelVariable="Buyer2SellerC" name="purchaseReply" operation="purchaseReply" >
			<participate toRole="SellerRole" relationshipType="BuyerSeller" fromRole="BuyerRole"/>
			<choice>
				<workunit name="Send purchase confirmation" repeat="false" guard="(creditCardValidity) >0 and (storeAmount) >0 ">
					<exchange action="respond" name="purchaseConfirm" informationType="creditCardCheckType">

					</exchange>
				</workunit>
				<workunit name="Send purchase reject" repeat="false" guard="(creditCardValidity) = 0 or (storeAmount) =0 ">
					<exchange action="respond" name="purchaseReject" informationType="creditCardCheckType">

					</exchange>
				</workunit>
			</choice>
		</interaction>		

推荐答案


有许多方法可用于读取C#中的XML.您可以使用System.Xml或System.Linq.Xml来读取XML.看看这些使用第一种方法的帖子:
http://www.c-sharpcorner.com/UploadFile/mahesh/ReadWriteXMLTutMellli2111282005041517AM/ReadWriteXMLTasp /a> [ ^ ]

将XmlReader类与C#一起使用 [
Hi,
There are many ways which can be used to read XML in C#. You can use System.Xml or System.Linq.Xml to read XML. Take a look at these post which the first method is used:
http://www.c-sharpcorner.com/UploadFile/mahesh/ReadWriteXMLTutMellli2111282005041517AM/ReadWriteXMLTutMellli21.aspx[^]

Using the XmlReader class with C#[^]

I hope it helps,
Cheers


这是代码.

Hi, Here is code.

 Using reader As XmlReader = XmlReader.Create(filenametextbox)
            While reader.Read()
                ' Check for start elements.
                If reader.IsStartElement() Then

                    ' Interaction (read attribute example name, initiate)
                    If reader.Name = "interaction" Then
                        'Console.WriteLine("Start <interaction> element.")
                        attr_name = reader("name")
                        attr_init = reader("initiate")
                        'If attr_name IsNot Nothing Then
                        'Console.WriteLine("  Has attribute name: {0}", attr_name)
                        'ElseIf attr_init IsNot Nothing Then
                        'Console.WriteLine("  Has attribute name: {0}", attr_init)
                        'End If

                        ' participate (read attribute example toRole, fromRole)
                    ElseIf reader.Name = "participate" Then
                        ' Get toRole,fromRole attribute.
                        attr_toRole = reader("toRole")
                        attr_fromRole = reader("fromRole")
                        from_to_role = ngoac1 & attr_fromRole & sym2 & attr_toRole & ngoac2
                       

                    ElseIf reader.Name = "workunit" Then
                        wk_guard = reader("guard")
                        If InStr(1, wk_guard, " or ") > 0 Then
                            wk_guard_tem = wk_guard.Replace(" or ", hoac)

                        End If
                        If InStr(1, wk_guard, " and ") > 0 Then
                            wk_guard_tem = wk_guard.Replace(" and ", va)
                        End If

                        

                        ' exchange (read attribute example name)
                    ElseIf reader.Name = "exchange" Then
                        attr_name = reader("name")
                        

                        
                        
                       
                       
                        

                        
                        ' send (read attribute example variable)
                    ElseIf reader.Name = "send" Then
                        attr_variable_send = reader("variable")
                        attr_variable_send_tem = Mid(attr_variable_send, 17, Len(attr_variable_send) - 17)
                        
                        ' receive (read attribute example variable)
                    ElseIf reader.Name = "receive" Then
                        attr_variable_receive = reader("variable")
                        attr_variable_receive_tem = Mid(attr_variable_receive, 17, Len(attr_variable_receive) - 17)
                        
                    End If
                Else
                    If reader.Name = "exchange" And reader.NodeType = XmlNodeType.EndElement Then
                        
                    End If
                End If
            End While
        End Using
</interaction>


这篇关于读取XML文件到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆