Solved

VB.NET help with function parsing XML

Posted on 2008-10-01
4
390 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now