Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, everybody!

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

example:

XML
<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>		
Posted

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
 
Share this answer
 
Hi, Here is code.

XML
 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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900