Server Reference Guide : ASOLib--OpenROAD Server Library : XML Parameters for Use with GSCPs : How You Can Retrieve XML from a GSCP
 
Share this page          
How You Can Retrieve XML from a GSCP
If you want the returned parameter data to be in XML format, specify a string variable named b_so_xml in the by-reference PDO. In the example, the client VB code would look like this:
Set byrefPDO = CreateObject("OpenROAD.ParameterData")
byrefPDO.DeclareAttribute "b_so_xml", "STRING"
After the GSCP is called, string variable b_so_xml will contain an XML document generated from the 4GL method's parameter names and values. The XML returned will contain a DTD detailing the structure of the XML. It will not contain an XML processing instruction as the first line; this is deliberate and allows the client to more easily specify any XSLT transformations.
Sample Output:
Sample output from the scp_GetAuthorAndBooks call follows:
<!DOCTYPE scp_getauthorandbooks [
   <!ELEMENT   scp_getauthorandbooks  (p_i_author_id*, b_UCAuthor*,
      b_arr_UCBooks*)>
    <!ELEMENT   p_i_author_id  (#PCDATA)>
    <!ELEMENT   b_UCAuthor  (i_age, i_id, v_name)>
    <!ELEMENT   i_age  (#PCDATA)>
    <!ELEMENT   i_id  (#PCDATA)>
    <!ELEMENT   v_name  (#PCDATA)>
    <!ELEMENT   b_arr_UCBooks  (arr_ucedition*, v_title, ucauthor?)>
    <!ELEMENT   arr_ucedition  (i_issue_no, i_year, m_cost, ucpublisher?)>
    <!ELEMENT   i_issue_no  (#PCDATA)>
    <!ELEMENT   i_year  (#PCDATA)>
    <!ELEMENT   m_cost  (#PCDATA)>
    <!ELEMENT   ucpublisher  (v_name)>
    <!ELEMENT   v_title  (#PCDATA)>
    <!ELEMENT   ucauthor  (i_age, i_id, v_name)>
]>
 <scp_getauthorandbooks>
    <p_i_author_id>101</p_i_author_id>
    <b_UCAuthor>
        <i_age>23</i_age>
        <i_id>101</i_id>
        <v_name>P.S.Eudonym</v_name>
    </b_UCAuthor>
    <b_arr_UCBooks>
        <arr_ucedition>
            <i_issue_no>1</i_issue_no>
            <i_year>1990</i_year>
            <m_cost>               $5.99</m_cost>
            <ucpublisher>
                <v_name>Raven &amp; Wolf Publishing</v_name>
            </ucpublisher>
        </arr_ucedition>
        <v_title>Horror Stories</v_title>
        <ucauthor>
            <i_age>23</i_age>
            <i_id>101</i_id>
            <v_name>P.S.Eudonym</v_name>
        </ucauthor>
    </b_arr_UCBooks>
    <b_arr_UCBooks>
        <arr_ucedition>
            <i_issue_no>1</i_issue_no>
            <i_year>1991</i_year>
            <m_cost>               $5.99</m_cost>
            <ucpublisher>
                <v_name>Raven &amp; Wolf Publishing</v_name>
            </ucpublisher>
        </arr_ucedition>
        <arr_ucedition>
            <i_issue_no>2</i_issue_no>
            <i_year>1994</i_year>
            <m_cost>               $6.99</m_cost>
            <ucpublisher>
                <v_name>Raven &amp; Wolf Publishing</v_name>
            </ucpublisher>
        </arr_ucedition>
        <v_title>More Horror Stories</v_title>
        <ucauthor>
            <i_age>23</i_age>
            <i_id>101</i_id>
            <v_name>P.S.Eudonym</v_name>
        </ucauthor>
    </b_arr_UCBooks>
</scp_getauthorandbooks>
Tag Structure
The outer tag is the name of the GSCP: scp_getauthorandbooks. The next level of tags represents the names of the declared 4GL parameters. For parameters that represent user classes, the attribute names of the user class are themselves tags nested within the user class tags.
Array parameters look the same as a single user class parameter, except that they repeat for each row in the array. In the preceding example, the parameter b_arr_UCBooks is an array of books with two elements. There are two sets of tags named b_arr_UCBooks at the same level. The attribute arr_UCEdition is an array attribute of the uc_book class, and in the first book, there is only one edition. In the second book element, two editions are available.
Note:  The publisher name has been escaped because the data value, Raven & Wolf Publishing, contains an ampersand character, which has a special meaning in XML documents.
Selective Output
By default all of the 4GL method's parameters appear in the generated XML document. Alternatively, you can specify exactly which parameters you want to appear in the output XML document by using the p_arr_UCXML_Include 4GL parameter. This is an array of a uc_xml_include class that has just one attribute v_parameter. Each v_parameter attribute should contain the name of the 4GL parameter that you want to include in the XML output.
For example, to receive only the b_UCAuthor data in the generated XML, the client code would look like this:
Set byrefPDO = CreateObject("OpenROAD.ParameterData")

byrefPDO.DeclareAttribute "b_so_xml", "STRING"
byrefPDO.DeclareAttribute "p_arr_UCXML_Include", "UCARRAY"
byrefPDO.DeclareAttribute "p_arr_UCXML_Include.v_parameter", "STRING"

byrefPDO.SetAttribute "p_arr_UCXML_Include[1].v_parameter", "b_UCAuthor"
After the call, the output XML looks like this:
<!DOCTYPE scp_getauthorandbooks [
        <!ELEMENT   scp_getauthorandbooks  (b_UCAuthor*)>
        <!ELEMENT   b_UCAuthor  (i_age, i_id, v_name)>
        <!ELEMENT   i_age  (#PCDATA)>
        <!ELEMENT   i_id  (#PCDATA)>
        <!ELEMENT   v_name  (#PCDATA)>
]>
<scp_getauthorandbooks>
        <b_UCAuthor>
                <i_age>23</i_age>
                <i_id>101</i_id>
                <v_name>P.S.Eudonym</v_name>
        </b_UCAuthor>
</scp_getauthorandbooks>