471,335 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,335 software developers and data experts.

Help with processing xml from an http api return

What would be the best way to process a return from an http api login
function that returns one of the following two XML streams?
Successful login with a session ID returned

<?xml version="1.0" encoding="UTF-8" ?>
<CreateSessionResponse>
<result>0</result>
<warning>CreateSession succeeded</warning>
<return>
<SessionID>1126765227212</SessionID>
</return>
</CreateSessionResponse>
Unsuccessful return with a fault code and message

<?xml version="1.0" encoding="UTF-8" ?>
<CreateSessionResponse>
<fault>
<faultcode>80004005</faultcode>
<faultstring>AgentIntegration error : Login failed. Reason is:
Invalid User Name or Password. Please try again.</faultstring>
</fault>
</CreateSessionResponse>

Jan 26 '06 #1
6 1223
You don't say if this is SOAP or just some sort of "plain XML" response
structure.
However, it looks like SOAP, but if you arent using a WebReference to the
WSDL and a WebService Proxy, it's still easy to see that both responses
represent a complete XmlDocument.

So, to keep things simple, I'd load it into an XmlDocument, and look
for the contents of the CreateSessionResponse node.
if
SelectSingleNode("//CreateSessionResponse/fault/faultcode").InnerText

is not null, you got a SOAP FAULT.

Conversely if

SelectSingleNode("//CreateSessionResponse/return/SessionID").InnerText

is not null, you got a Session.

hope that makes sense.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"mnvikefan" wrote:
What would be the best way to process a return from an http api login
function that returns one of the following two XML streams?
Successful login with a session ID returned

<?xml version="1.0" encoding="UTF-8" ?>
<CreateSessionResponse>
<result>0</result>
<warning>CreateSession succeeded</warning>
<return>
<SessionID>1126765227212</SessionID>
</return>
</CreateSessionResponse>
Unsuccessful return with a fault code and message

<?xml version="1.0" encoding="UTF-8" ?>
<CreateSessionResponse>
<fault>
<faultcode>80004005</faultcode>
<faultstring>AgentIntegration error : Login failed. Reason is:
Invalid User Name or Password. Please try again.</faultstring>
</fault>
</CreateSessionResponse>

Jan 26 '06 #2
These are not soap messages. There is no web reference to a wsdl.
However, thankyou for the comments about loading the documents into an
XmlDocument object and using the SelectSingleNode method. I think that
this will help me very much. I was wondering if I should use an
XmlTextReader to get the data and while that would have worked, I don't
think it is as straight forward as the method you just presented me.

Jan 27 '06 #3
You can and should consider using an XmlTextReader, as it is more efficient.
I was just trying to bring it down to a "lowest common denominator".
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"mnvikefan" wrote:
These are not soap messages. There is no web reference to a wsdl.
However, thankyou for the comments about loading the documents into an
XmlDocument object and using the SelectSingleNode method. I think that
this will help me very much. I was wondering if I should use an
XmlTextReader to get the data and while that would have worked, I don't
think it is as straight forward as the method you just presented me.

Jan 27 '06 #4
For the most part, your suggestion below is working, but now I am
having a weird issue with the following XML return.

<?xml version="1.0" encoding="UTF-8" ?>
<ActivateWithTextResponse>
<result>0</result>
<warning>ActivateWithText succeeded</warning>
<return>
<NumberConcepts>33</NumberConcepts>
</return>
</ActivateWithTextResponse>

Here is the error segment that I am receiving...

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:
Line 104: {
Line 105: labelMessage.Text =
document.SelectSingleNode("//ActivateWithTextResponse/warning").InnerTex
t;
Line 106: TextBox1.Text =
document.SelectSingleNode("//ActivatetWithTextResponse/result/NumberConc
epts").InnerText;
Line 107: }
Line 108: }
Source File: c:\inetpub\wwwroot\helpdesk\search.aspx.cs Line: 106
Not sure why line 106 is giving me problems and line 105 is not.

Peter Bromberg [C# MVP] wrote:
You don't say if this is SOAP or just some sort of "plain XML"
response structure.
However, it looks like SOAP, but if you arent using a WebReference to
the WSDL and a WebService Proxy, it's still easy to see that both
responses represent a complete XmlDocument.

So, to keep things simple, I'd load it into an XmlDocument, and look
for the contents of the CreateSessionResponse node.
if
SelectSingleNode("//CreateSessionResponse/fault/faultcode").InnerText

is not null, you got a SOAP FAULT.

Conversely if

SelectSingleNode("//CreateSessionResponse/return/SessionID").InnerText

is not null, you got a Session.

hope that makes sense.

Peter

--

Jan 29 '06 #5
There is nothing weird about this - you just can't type

"ActivatetWithTextResponse/result/NumberConcepts"
^ ^^^^^^

Always check your paths.

I suggest that you knock up a small app to load a doc and highlight the
nodes selected by a path - it is quite simple and I find it extremely useful
when the expressions get more complicated.

"GeekCIA" <So*****@somewhere.com> wrote in message
news:XO********************@comcast.com...
For the most part, your suggestion below is working, but now I am
having a weird issue with the following XML return.

<?xml version="1.0" encoding="UTF-8" ?>
<ActivateWithTextResponse>
<result>0</result>
<warning>ActivateWithText succeeded</warning>
<return>
<NumberConcepts>33</NumberConcepts>
</return>
</ActivateWithTextResponse>

Here is the error segment that I am receiving...

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:
Line 104: {
Line 105: labelMessage.Text =
document.SelectSingleNode("//ActivateWithTextResponse/warning").InnerTex
t;
Line 106: TextBox1.Text =
document.SelectSingleNode("//ActivatetWithTextResponse/result/NumberConc
epts").InnerText;
Line 107: }
Line 108: }
Source File: c:\inetpub\wwwroot\helpdesk\search.aspx.cs Line: 106
Not sure why line 106 is giving me problems and line 105 is not.

Peter Bromberg [C# MVP] wrote:
You don't say if this is SOAP or just some sort of "plain XML"
response structure.
However, it looks like SOAP, but if you arent using a WebReference to
the WSDL and a WebService Proxy, it's still easy to see that both
responses represent a complete XmlDocument.

So, to keep things simple, I'd load it into an XmlDocument, and look
for the contents of the CreateSessionResponse node.
if
SelectSingleNode("//CreateSessionResponse/fault/faultcode").InnerText

is not null, you got a SOAP FAULT.

Conversely if

SelectSingleNode("//CreateSessionResponse/return/SessionID").InnerText

is not null, you got a Session.

hope that makes sense.

Peter

--

Jan 30 '06 #6

That didn't format correctly:

1) you have an extra 't' at the end of Activate
2) NumberConcepts is in the return node not the result node

"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message
news:8v********************@fe3.news.blueyonder.co .uk...
There is nothing weird about this - you just can't type

"ActivatetWithTextResponse/result/NumberConcepts"
^ ^^^^^^

Always check your paths.

I suggest that you knock up a small app to load a doc and highlight the
nodes selected by a path - it is quite simple and I find it extremely
useful when the expressions get more complicated.

"GeekCIA" <So*****@somewhere.com> wrote in message
news:XO********************@comcast.com...
For the most part, your suggestion below is working, but now I am
having a weird issue with the following XML return.

<?xml version="1.0" encoding="UTF-8" ?>
<ActivateWithTextResponse>
<result>0</result>
<warning>ActivateWithText succeeded</warning>
<return>
<NumberConcepts>33</NumberConcepts>
</return>
</ActivateWithTextResponse>

Here is the error segment that I am receiving...

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:
Line 104: {
Line 105: labelMessage.Text =
document.SelectSingleNode("//ActivateWithTextResponse/warning").InnerTex
t;
Line 106: TextBox1.Text =
document.SelectSingleNode("//ActivatetWithTextResponse/result/NumberConc
epts").InnerText;
Line 107: }
Line 108: }
Source File: c:\inetpub\wwwroot\helpdesk\search.aspx.cs Line: 106
Not sure why line 106 is giving me problems and line 105 is not.

Peter Bromberg [C# MVP] wrote:
You don't say if this is SOAP or just some sort of "plain XML"
response structure.
However, it looks like SOAP, but if you arent using a WebReference to
the WSDL and a WebService Proxy, it's still easy to see that both
responses represent a complete XmlDocument.

So, to keep things simple, I'd load it into an XmlDocument, and look
for the contents of the CreateSessionResponse node.
if
SelectSingleNode("//CreateSessionResponse/fault/faultcode").InnerText

is not null, you got a SOAP FAULT.

Conversely if

SelectSingleNode("//CreateSessionResponse/return/SessionID").InnerText

is not null, you got a Session.

hope that makes sense.

Peter

--


Jan 30 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Maxwell Hammer | last post: by
reply views Thread by charles hamm | last post: by
7 posts views Thread by Tigger | last post: by
1 post views Thread by Rahul | last post: by
8 posts views Thread by pamelafluente | last post: by
15 posts views Thread by Jay | last post: by
2 posts views Thread by rookiejavadude | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.