Guys
I am finding difficulty accessing the values of XML data supplied from a webservice call (to a SAP ABAP webservice). I am using LiveCycle 8.2 and javascript. The web service itself uses Document style binding in the WSDL. My javascript specifies XML binding (though I have also tried Message and JS style binding.)
When I execute the webservice call, I can use SOAP.wireDump = true; to see the contents of the XML returned (see a brief excerpt below):
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header></soap-env:Header>
<soap-env:Body><n0:ZFMWSResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<Contents>
<Item>
<Name>String</Name>
</Item>
</Contents>
<ReturnContents>
<Item>
<Name>String1</Name>
<Item>
<Item>
<Name>String2</Name>
</Item>
</ReturnContent>
etc etc
This XML is stored within a variable called "result".
Now it gets interesting. I can easily access the value of the <Contents><Item><Name> </Name> string (i.e. String1) using the following javascript syntax:
console.println(result.Contents.Item.Name);
This syntax (i.e. result.Contents.Item.Name) also works when I display the result in a form text field.
This is slightly curious as I would have anticipated that .value or .soapValue would be required to access the value, but no, simply using the syntax above retrieves the value.
Why this works I am unsure. However. When there is more than one repeating value in the XML i.e. there are two <Item> instances in <ReturnContents>, I cannot find a valid syntax to access any of their values.
For example,
console.println(result.ReturnContents.Item[0].Name); does not work!
I do not seem to be able to find any syntax that accesses the value of <Item> when there are multiple instances of Item in the XML.
I have tried many things including trying to parse the contents or result into XML i.e.:
var myXML = XMLData.parse(result, false);
var a = XMLData.applyXPath(result, "//item");
a.saveXML('pretty');
If this worked, I could then easily navigate through to the values I need.
etc etc.
However this always causes an error. When this script runs the contents of 'result' (which is storing the XML returned from the webservice) always appear to be empty. The error is: Xml parsing error: no element found (error code 3).
Does anyone have any ideas? The main problem seems to be that I cannot properly access the properties of the 'result' variable which holds the XML returned from the web service.
The only property of this 'result' vairable which returns something other than null or empty is:
result.ReturnContents.length;
This then returns the number of <Items> under the <ReturnContents> node. However, result.ReturnContents.value (or any similar syntax) always returns empty.
What is the syntax to access multiple <Items> under <ReturnContents>?
Any thoughts would be very much appreciated!
Thanks
Roxy