?
Solved

Get string into xmldatadocument

Posted on 2003-02-28
6
Medium Priority
?
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

764 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