Solved

VB.NET help with function parsing XML

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

Suggested Solutions

Title # Comments Views Activity
Word Directory is not in the drop down list 4 25
Angular JS Route 3 47
Ajax Panel Not Updating When Triggered By Timer 4 40
Exit the loop 4 34
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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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.

911 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

19 Experts available now in Live!

Get 1:1 Help Now