Solved

VB.NET help with function parsing XML

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

Industry Leaders: 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

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.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 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