0

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
  • There's no XML datatype in .NET. Can you be a little more specific? Give an example of how the XML looks like and what attribute/value you'd like to obtain from it. Also why is this tagged with flash, axshockwaveflash and call? Commented Mar 1, 2010 at 18:11
  • @Darin - the XML is coming from an axshockwaveflash control. Commented Mar 1, 2010 at 22:10

2 Answers 2

2
Dim doc As XDocument = XDocument.Parse(str)
Sign up to request clarification or add additional context in comments.

1 Comment

This gets me the XML string into an XML object. I still can't call the function... It's a start though.
2

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

8 Comments

And how can I call the function whose name is stored in val?
@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.
@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 - 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: 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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.