views:

195

answers:

2

I am trying to parse a particular attribute/value pair from XML in VB.NET.

The XML is originally a string that looks like XML but it needs to be converted to an XML-like datatype or structure before I can parse it.

How can I convert this string into XML, and then parse the info that I need?

EDIT:

Dim doc As XDocument = XDocument.Parse(str) gets the string into xml, however Call doc.attribute("name").Value doesn't work. I've confirmed that the name of the Sub that I'm trying to call is correct. What am I doing wrong?

I've tried converting the value of the XML back into a string. Is here a special datatype for Subs? Am I missing something else?

Edit2 The value of the XML attribute is the name of a function. I'd like to call different functions based on the value of the value, which will be changed by me via a flash activex control. I pretty much have total control over what values i'm dealing with here.

(Do I need a delegate function? )

Edit3:

I got it. 'CallByName()' with appropriate arguments.

+2  A: 
Dim doc As XDocument = XDocument.Parse(str)
Luhmann
This gets me the XML string into an XML object. I still can't call the function... It's a start though.
Moshe
+2  A: 

What function are you talking about calling? "Value"? That's not a function. It's a property.

Dim val As Object = doc.Attribute("name").Value
John Saunders
And how can I call the function whose name is stored in val?
Moshe
@Moshe: you never said you have the name of a function stored in the XML. I have no idea how to call a function whose name is stored in a string, I only know it's usually a bad idea to play such games.
John Saunders
See edits. Thanks though. +1
Moshe
@Moshe: if there are a limited number of possible functions, then just use a switch statement. I strongly suggest you not try to get fancy with doing dynamic function calls through reflection or something. That can be very difficult to maintain.
John Saunders
@John - I would have to disagree on both counts. Dynamic function calls are easier than a switch statement to maintain because I won't forget to add cases. Also, there are an unknown number of functions at this point. Thanks.
Moshe
@Moshe: dynamic function calls are tougher to maintain because they need to be maintained by someone who uderstands dynamic function calls. A far larger number of developers know what a switch statement is.
John Saunders
@John - ah. I didn't understand you before in regards to mauntaining it. This happens to be a (proprietary) program fo r myself. The idea is that I won't need to rely on swf studio or flash jester to make Flash access system functions like a regular desktop app. I don't know what functions exactly I need except that they are likely to change, hence dynamic function calls.
Moshe
@Moshe: good luck. In most shops, not everyone knows Reflection. In yours, everyone already does.
John Saunders
@ John - Reflection? Is that the term for dynamic functions? Cool, you live and learn. Thanks for your time.
Moshe
@Moshe: see http://msdn.microsoft.com/en-us/library/cxz4wk15.aspx
John Saunders