?
Solved

VB.NET help with function parsing XML

Posted on 2008-10-01
4
Medium Priority
?
413 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
[X]
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
  • 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

777 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