Get string into xmldatadocument

Ok here goes...

I have a web service that returns a custom xml string.
Something like this:

<NewDataSet>
<Success>True</Success>
<Error>No errors</Error>
<DateTime>2/28/2003 8:55:57AM</DateTime>
<Service>NewService</Service>
<Method>NewMethod</Method>
<MiscData />
<xmlData>
 <Data> <data1>1234</data1> <data2>875</data2> </Data>
</xmlData>
</NewDataSet>

Now what I would like to do is get this string back to my asp.net app and then grab the data2 value from the string.  But in order to do this, I need to be able to load this string into an xmldatadocument.  At least that is what I think but I'm not sure.  Anyway, can someone post a code snippet in VB that shows how to load the string into the object and how to get the data2 value back out and put into a string?  If this is not enough info, please let me know and I will provide any additional info.
mleopardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

a_goatCommented:
You need to add a reference in your .net application to the Microsoft DOM 4.0 library (I strongly suggest 4.0, but if you want/need to you can use another).

DOMDocument = new MSXML2.DOMDocument40
DOMDocument.loadxml(XMLString)
DataValue = DOMDocument.selectSingleNode("//data2")
if not DataValue is nothing then
    Result = DataValue.text
end if

XMLString is the xml and Result is the value of data2 if it exists.

I didn't bother putting in the error checking, but I think you can just look at DOMDocument.parseError.errorCode and if it's 0, there was no error loading the xml.
0
mleopardAuthor Commented:
Thanks for the help.   I guess I should have been a little more clear. My xml coming back from the web service is a string (defined in the web service method as a string) so it actually looks something like this:

myStr="<NewDataSet>
<Success>True</Success>
<Error>No errors</Error>
<DateTime>2/28/2003 8:55:57AM</DateTime>
<Service>NewService</Service>
<Method>NewMethod</Method>
<MiscData />
<xmlData>
<Data> <data1>1234</data1> <data2>875</data2> </Data>
</xmlData>
</NewDataSet>"

So when I tried to load the xml string into the DOMDocument, it broke.  So I assume that in the example, I would need to pass an xml stream?  Sorry for my ignorance, I am still very new to this.  Thanks
0
mleopardAuthor Commented:
BTW is the variable DataValue defined as a string?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

a_goatCommented:
No, It's particlarly written to take a string, so instead of XMLString, you'd just need to pass myStr.

I'm going to guess that it's the line where you load the xml that's a problem.

Check DOMDocument.parseError.Reason right after the loadxml line.  That should tell you why it's not loading.  It may be something simple like a field not closed.  It also has parameters like "line", "linepos", "url", and "srcText" which should help you track a problem with the xml.

If that's not the problem, my code may be off slightly.  If you can tell me exactly which line I can track it down (I'm not at a machine with .net installed)

Also, if your data is coming back from a web service, you may want to use the XML DOM HTTP object to retrieve it for you.  If you do so, that automatically builds an xml document for you, and still gives you access to the raw text.

DataStream = new MSXML2.ServerXMLHTTP
DataStream.open "http://webservice", false
myStr = DataStream.responseText
myDOM = DataStream.responseXML

DataValue = myDOM.selectSingleNode("//data2")
if not DataValue is nothing then
   Result = DataValue.text
end if


myStr is optional here as it's just the plain text response.  Again, you can check for loading errors by looking at myDOM.parseError.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
a_goatCommented:
No, DataValue is an IDOMNode object.  That may be it
0
mleopardAuthor Commented:
Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.