Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB.NET help with function parsing XML

Posted on 2008-10-01
4
400 Views
Last Modified: 2010-04-21
I am having trouble creating a function that will be able to parse specific XML data & raise events based on the contents. I've attached an example XML string.

Desired end result would be a function like:

ParseXMLData(sData)

Basically it should parse the INT_ACTION lines and raise events for CALL, PUSH & TALK

Then I'd like it to raise events like:

RaiseEvent onCall(sUser, sAct, sArea, sSatic, sMethod, sDial, sKey)
RaiseEvent onPush(sUser, sAct, sArea, sSatic, sPerm, sDial, sKey)
RaiseEvent onTalk(sUser, sAct, sArea, sSatic, sPad, sDial, sKey)

As of right now I am just trying to use some simple string functions but I realized there has to be a better way... any help would be greatly appreciated
<USER_ACTIONS>
	<INT_ACTION user="samson411" act="CALL" area="" static="" method="" dial="7">telephone</INT_ACTION>
	<INT_ACTION user="jonesj" act="PUSH" area="" static="" perm="1" dial="">empty</INT_ACTION>
	<INT_ACTION user="genie23" act="TALK" area="23" static="" pad="" dial="">sup</INT_ACTION>
	<INT_ACTION user="handymanNY" act="CALL" area="" static="" method="" dial="OP">telephone</INT_ACTION>
</USER_ACTIONS>

Open in new window

0
Comment
Question by:mcainc
  • 2
  • 2
4 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 22613366
Hello mcainc,

It would be something like this:

Regards,

TimCottee
Imports System.Xml
Imports System.Xml.XmlDocument 
Public Event ........ 
Public Sub ParseXMLData(ByVal sData As String) 
 Dim xData As XmlDocument = New XmlDocumetn
 xData.LoadXml(sData)
 For Each xAction In xData.SelectNodes("USER_ACTIONS/INT_ACTION")
   Select Case xAction.Attributes("act").InnerText
   Case "CALL"
    RaiseEvent onCall(xAction.Attributes("user").InnerText,xAction.Attributes("act").InnerText, xAction.Attributes("static").InnerText, xAction.Attributes("method").InnerText, xAction.Attributes("dial").InnerText, xAction.InnerText)
   Case "PUSH"
   ....
   End Select
 Next
 xData = Nothing
End Sub
  

Open in new window

0
 

Author Comment

by:mcainc
ID: 22613460
thanks tim,

i'm getting an error here: Select Case xAction.Attributes("type").InnerText

A first chance exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll

Property InnerText is WriteOnly

any idea?
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 22613529
mcainc,

For Each xAction As XmlNode In xData.SelectNodes("USER_ACTIONS/INT_ACTION")

Without the declaration it raises this error, I was obviously typing too quickly and missed it out.

TimCottee
0
 

Author Closing Comment

by:mcainc
ID: 31501927
perfect!!!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question