Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Get string into xmldatadocument

Posted on 2003-02-28
6
Medium Priority
?
272 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:mleopard
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:a_goat
ID: 8041831
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
 

Author Comment

by:mleopard
ID: 8041989
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
 

Author Comment

by:mleopard
ID: 8042088
BTW is the variable DataValue defined as a string?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Accepted Solution

by:
a_goat earned 400 total points
ID: 8042129
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
 
LVL 3

Expert Comment

by:a_goat
ID: 8042134
No, DataValue is an IDOMNode object.  That may be it
0
 

Author Comment

by:mleopard
ID: 8043505
Thanks for your help.
0

Featured Post

Independent Software Vendors: 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 crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

577 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