Link to home
Start Free TrialLog in
Avatar of mleopard
mleopard

asked on

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.
Avatar of a_goat
a_goat

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.
Avatar of mleopard

ASKER

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
BTW is the variable DataValue defined as a string?
ASKER CERTIFIED SOLUTION
Avatar of a_goat
a_goat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No, DataValue is an IDOMNode object.  That may be it
Thanks for your help.