[U2] UV Basic parsing xml with XDOM commands

2013-11-05 Thread Peter Cheney
Hi Everyone,

Thought I'd post a solution to a task I've been working on in the hope it will 
assist someone else with similar requirements. Thanks also to those who've 
previously posted on this as I found the following to be most helpful as well:
http://www.mail-archive.com/u2-users@listserver.u2ug.org/msg18895.html
https://gdoesu2.wordpress.com/tag/xdomlocate/
http://listserver.u2ug.org/pipermail/u2-users/2010-September/004713.html
http://www.mvdeveloper.com/kb/docs/kb10.pdf


I had to parse some xml returned via a soap request to an IIS server:
?xml version=1.0?
s:Envelope xmlns:s=http://schemas.xmlsoap.org/soap/envelope/;
  s:Body
SuggestResponse xmlns=http://tempuri.org/;
  SuggestResult 
xmlns:a=http://schemas.datacontract.org/2004/07/FirstMac.Services.Category.Contracts;
 xmlns:i=http://www.w3.org/2001/XMLSchema-instance;
a:CategoryGroupSome group data/a:CategoryGroup
a:CategoryNameSome name data/a:CategoryName
  /SuggestResult
/SuggestResponse
  /s:Body
/s:Envelope
There are only ever 2 value nodes returned if the soap query is successful with 
the SuggestResult node containing 'i:nil=true' if the query is not successful.
e.g. SuggestResult i:nil=true ... /

The xml contains a default namespace and after much searching and trial and 
error I discovered I needed to use the following xpathString and nsMAP 
parameters in the XDOMLocate function:
Notes re the XDOMLocate function.
I found the UV11.1 Basic Commands Reference and Basic Extensions documents for 
XDOMLocate to be scarce on detail for the following:

  *   Each additional namespace in the string must also be space delimited.
  *   The double quotes enclosing the http url must be removed for each 
namespace defined in the nsMAP parameter. The description given has double 
quotes in the wrong places. e.g. if you have s:Envelope 
xmlns:s=http://schemas.xmlsoap.org/soap/envelope/; then the namespace you 
need to specify is nsMAP = 'xmlns:s=http://schemas.xmlsoap.org/soap/envelope/'

code
xpathStr  = '/s:Envelope/s:Body'

nsMAP  = 'xmlns:s=http://schemas.xmlsoap.org/soap/envelope/ '
nsMAP := 
'xmlns:a=http://schemas.datacontract.org/2004/07/FirstMac.Services.Category.Contracts
 '
nsMAP := 'xmlns=http://tempuri.org/ '
nsMAP := 'xmlns:i=http://www.w3.org/2001/XMLSchema-instance'

OK = XDOMOpen( RespData, XML.FROM.STRING, hDOM )
if OK = XML.SUCCESS then
   crt 'XML document opened'
   OK = XDOMLocate( hDOM, xpathStr, nsMAP, hRoot )
   if OK = XML.SUCCESS then
  crt 'Found ':xpathStr

  OK = XDOMGetNodeName( hRoot, NodeName )
  crt 'Root node=':NodeName
  OK = XDOMLocateNode( hRoot, XDOM.CHILD, XDOM.FIRST.CHILD, 
XDOM.ELEMENT.NODE, hParent )
  if OK = XML.SUCCESS then
 OK = XDOMGetNodeName( hParent, NodeName )
 crt 'Parent node = ':NodeName ;* 
'SuggestResponse'
 OK = XDOMLocateNode( hParent, XDOM.CHILD, XDOM.FIRST.CHILD, 
XDOM.ELEMENT.NODE, hChild )
 if OK = XML.SUCCESS then
OK = XDOMGetNodeName( hChild, NodeName )
crt 'Child node = ':NodeName   ;* 
'SuggestResult'
OK = XDOMLocateNode( hChild, XDOM.CHILD, XDOM.FIRST.CHILD, 
XDOM.ELEMENT.NODE, hValueNode )
if OK = XML.SUCCESS then
   OK = XDOMGetNodeName( hValueNode, NodeName )
   crt 'Value node1 = ':NodeName   ;* 
'a:CategoryGroup'
   OK = XDOMLocateNode(hValueNode, XDOM.CHILD, XDOM.FIRST.CHILD, 
XDOM.TEXT.NODE, hTextNode )
   if OK = XML.SUCCESS then
  OK = XDOMGetNodeValue(hTextNode, Value )
  crt 'Payload1 = ':Value  ;* 'Some group 
data'
   end else
  gosub ShowError
   end
end
OK = XDOMLocateNode( hChild, XDOM.CHILD, 2, XDOM.ELEMENT.NODE, 
hValueNode )
if OK = XML.SUCCESS then
   OK = XDOMGetNodeName( hValueNode, NodeName )
   crt 'Value node2 = ':NodeName   ;* 
'a:CategoryName'
   OK = XDOMLocateNode(hValueNode, XDOM.CHILD, XDOM.FIRST.CHILD, 
XDOM.TEXT.NODE, hTextNode )
   if OK = XML.SUCCESS then
  OK = XDOMGetNodeValue(hTextNode, Value )
  crt 'Payload2 = ':Value  ;* 'Some name 
data'
   end else
  gosub ShowError
   end
end else
   gosub ShowError
end
 end else
gosub ShowError
 end
  end else
 gosub ShowError
  end
   end
   OK = XDOMClose(hDOM)
end
return
*
ShowError:
OK = XMLGetError(Code, ErrText)
Crt Code = :Code
Crt Text = :ErrText
return
/code

Program Output:
XML document opened
Found /s:Envelope/s:Body
Root node=s:Body
Parent node = SuggestResponse
Child node = SuggestResult
Value node1 = a:TagGroup
Payload1 = Household expenses
Value node2 = a:TagName
Payload2 = Telephone / mobile


A 

Re: [U2] Web Services at Universe 11.n

2013-11-05 Thread andy baum
Richard,

You don't say what version of Universe you are on but if it is 10.n then the 
default http version is 1.0 most web services I have accessed need version 1.1 
so you will need to use :-

STATUS = setHTTPDefault(VERSION, 1.1)


At 11.n it looks like the default version has been changed to 1.1

HTH,
Andy



 From: Richard Lewis rbl...@gmail.com
To: U2 Users List u2-users@listserver.u2ug.org 
Sent: Wednesday, 30 October 2013, 22:42
Subject: Re: [U2] Web Services at Universe 11.n
 

Yes, as I said, I've tested with curl and it works perfectly.  The problem
I have is not being able to clearly/cleanly see the raw text being sent by
the uv functions, in order to determine the difference in what curl sends
(success) and what the uv functions send (failure).  There may be certain
idiosyncratic parsing involved in the service I am trying to consume, but I
have no control over that.  With curl I can see the entire conversation if
the logging is set correctly.  With the uv functions, even with the highest
logging level, it doesn't appear that the logging is actually that complete
and exact.  I have never had the impression that it was.

I would love to be able to do it all in uv, but I only have control over
half of the conversation, and with the uv functions, I seem to have a bit
less than half.

Richard


On Wed, Oct 30, 2013 at 2:12 PM, Symeon Breen syme...@gmail.com wrote:

 That means you where probably missing a header.   http is just a text
 conversation, if the same headers are passed as passed with curl it will
 work. You can test using curl, or even better with telnet.

 -Original Message-
 From: u2-users-boun...@listserver.u2ug.org
 [mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Richard Lewis
 Sent: 30 October 2013 20:03
 To: U2 Users List
 Subject: Re: [U2] Web Services at Universe 11.n

 I've recently been tasked with accessing a webservice, and couldn't get a
 valid response from the webservice.  It kept not recognizing the headers
 that were sent, and with the maximum logging set on the uv side, it looked
 like everything was being sent just fine, but the webservice still failed
 it.  I switched to using curl, and it all worked perfectly.

 Richard Lewis



 On Wed, Oct 30, 2013 at 1:00 PM, Oaks, Harold
 harold.o...@clark.wa.govwrote:

  I've been telling my boss that if we upgraded to Universe 11.23, we can
  implement web services.   (We're currently on 10.2)
  But,  finally looking in detail at the appropriate manual  (Universe
  Web Services Developer) it seems that one can publish a web service
  easily enough so that Universe data can be gotten, but I don't see
  that the other side is implemented, where one accesses an external web
  service and brings back data into Universe.  Am I missing the something?
 
  What are any of you using to fully implement web services with an
  underlying Universe environment?
  Thanks-
  Harold Oaks
  Sr. Analyst/Programmer
  Clark County, WA
 
  This e-mail and related attachments and any response may be subject to
  public disclosure under state law.
  ___
  U2-Users mailing list
  U2-Users@listserver.u2ug.org
  http://listserver.u2ug.org/mailman/listinfo/u2-users

 
 ___
 U2-Users mailing list
 U2-Users@listserver.u2ug.org
 http://listserver.u2ug.org/mailman/listinfo/u2-users

 ___
 U2-Users mailing list
 U2-Users@listserver.u2ug.org
 http://listserver.u2ug.org/mailman/listinfo/u2-users

___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users
___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users