Focal Point
[SOLVED] Custom XML output

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2467080206

April 13, 2011, 04:16 PM
Troy_proffitt
[SOLVED] Custom XML output
I am trying to populate a JQuery script using xml output from a fex. The output needs to look like this:

<?xml version="1.0" encoding="utf-8" ?> 
- <navigation>
- <navItem title="ENGLAND">
  <subNavItem url="JAGUAR.html" title="JAGUAR" /> 
  <subNavItem url="JENSEN.html" title="JENSEN" /> 
  <subNavItem url="TRIUMPH.html" title="TRIUMPH" /> 
  </navItem>
- <navItem title="JAPAN">
  <subNavItem url="DATSUN.html" title="DATSUN" /> 
  <subNavItem url="TOYOTA.html" title="TOYOTA" /> 
  </navItem>
- <navItem title="ITALY">
  <subNavItem url="ALPHA_ROMEO.html" title="ALPHA ROMEO" /> 
  <subNavItem url="MASERATI.html" title="MASERATI" /> 
  </navItem>
  </navigation>  


Any ideas? This needs to be called by the HTML page and return as XML data.

Thanks,
-Troy

This message has been edited. Last edited by: Kerry,


WF version 8105
all output
April 13, 2011, 05:06 PM
Norb Eckert
How were you going to get output produced from a fex? Whenever I create custom XML with WebFOCUS I have to use WRITE commands to create a file and then read it in via javascript.

Lately, I've been using JQuery to read WebFOCUS formatted XML output that is returned using the command: ON TABLE PCHOLD FORMAT XML


prod:7.6.9, win2k3 mre, caster, bid, devstudio 7.6.9
April 13, 2011, 05:33 PM
<FreSte>
I think it can be done using ON TABLE HOLD FORMAT WP


-Fred-

DEFINE FILE CAR
  LINE1/A50 = '<navItem title="' || COUNTRY || '"> ';
  LINE2/A80 = '<subNavItem url="' || CAR || '.HTML" title="' || CAR || '" />';
  LINE3/A20 = '</navItem>';
END

TABLE FILE CAR
  BY COUNTRY NOPRINT
  BY LINE2 AS ''
  ON COUNTRY SUBHEAD
  "<LINE1"
  ON COUNTRY SUBFOOT
  "<LINE3"
  ON TABLE HOLD AS RPRT FORMAT WP
  ON TABLE SET PAGE NOPAGE
END
-RUN


SET HTMLFORMTYPE=TXT
-HTMLFORM BEGIN
<?xml version="1.0" encoding="utf-8" ?>
<navigation>
  !IBI.FIL.RPRT;
</navigation>
-HTMLFORM END
-EXIT

April 14, 2011, 09:01 AM
Troy_proffitt
That is perfect FreSte. Thanks so much


WF version 8105
all output
April 14, 2011, 10:17 AM
dhagen
An alternative (this might only be available in 77 however):

Master:
FILENAME=WSDEMO_XMLTEST, SUFFIX=XML     ,
 DATASET=wsdemo/xmltest.xml, $
  SEGMENT=NAVIGATION, SEGTYPE=S0, $
    FIELDNAME=NAVIGATION, ALIAS=navigation, USAGE=A1, ACTUAL=A1, ACCESS_PROPERTY=(INTERNAL), $
  SEGMENT=NAVITEM, SEGTYPE=S0, PARENT=NAVIGATION, $
    FIELDNAME=NAVITEM, ALIAS=navItem, USAGE=A1, ACTUAL=A1, ACCESS_PROPERTY=(INTERNAL),
      REFERENCE=NAVIGATION, PROPERTY=ELEMENT,  $
    FIELDNAME=TITLE, ALIAS=title, USAGE=A70, ACTUAL=A70,
      REFERENCE=NAVITEM, PROPERTY=ATTRIBUTE,  $
  SEGMENT=SUBNAVITEM, SEGTYPE=S0, PARENT=NAVITEM, $
    FIELDNAME=SUBNAVITEM, ALIAS=subNavItem, USAGE=A1, ACTUAL=A1, ACCESS_PROPERTY=(INTERNAL),
      REFERENCE=NAVITEM, PROPERTY=ELEMENT,  $
    FIELDNAME=SUBURL, ALIAS=url, USAGE=A70, ACTUAL=A70,
      REFERENCE=SUBNAVITEM, PROPERTY=ATTRIBUTE,  $
    FIELDNAME=SUBTITLE, ALIAS=title, USAGE=A70, ACTUAL=A70,
      REFERENCE=SUBNAVITEM, PROPERTY=ATTRIBUTE,  $
  


Fex to build xml:
-*new file
TABLE FILE ibisamp/CAR
PRINT 
COMPUTE TITLE/A70= COUNTRY;
COMPUTE SUBURL/A70= CAR || '.htm';
COMPUTE SUBTITLE/A70= CAR;
BY COUNTRY NOPRINT
ON TABLE HOLD AS TEST FORMAT ALPHA
ON TABLE SET HOLDLIST PRINTONLY
END
-RUN
 
CREATE FILE XMLTEST DROP 
MODIFY FILE XMLTEST
MATCH TITLE
ON MATCH CONTINUE
ON NOMATCH INCLUDE
MATCH SUBURL
ON MATCH INCLUDE
ON NOMATCH INCLUDE
FIXFORM FROM TEST
DATA ON TEST
END
-RUN
 
EX EDAGET XML,wsdemo/xmltest,T
-RUN
  



"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
April 14, 2011, 10:27 AM
Clif
Support for XML output is built in to DataMigrator and requires no coding. From the DMC create a synonym, say NAVIGATION, for the xml checking "Make Unique" so that the second TITLE element gets named TITLE1. In the synonym editor change the length of the fields from the default A10 to A16 for TITLE1 and A21 for URL.

Then create a data flow with CAR as source and NAVIGATION as target. In SQL select CAR and COUNTRY. In the target transformations map
TITLE = COUNTRY
URL = CAR||'.html'
TITLE1 = CAR
Submit and you are done.


N/A
April 14, 2011, 10:29 AM
dhagen
Nicely put!


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
April 14, 2011, 01:10 PM
Norb Eckert
@FreSte - that's pretty slick. I'm gonna use that coding technique. Thanks.


prod:7.6.9, win2k3 mre, caster, bid, devstudio 7.6.9
April 14, 2011, 02:17 PM
Francis Mariani
You can't call DataMigrator to populate a JQuery script that's in an HTML page.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
April 14, 2011, 02:32 PM
Troy_proffitt
So if I wanted to call this fex (with xml output) from a Jquery script, does anyone have a sample of how it would work (from an HTML page)?


WF version 8105
all output
April 14, 2011, 04:22 PM
<FreSte>
Troy,

Below an example how to do it.
I saved the fex (see my post above) as cardata_as_xml.fex in my baseapp folder and
the code below was also saved in baseapp as xml_jquery.htm

And url is: http://localhost:8080/approot/baseapp/xml_jquery.htm

Cheers,

-Fred-



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Demo jQuery / WebFOCUS</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

    <style>
    body {
        font-family:verdana;
        font-size:14px;
    }
    .data {
        padding:20px;
    }
    .navItem {
        color   : navy;
        font-size:18px;
    }

    .subNavItem {
        padding-left:20px;
    }
    </style>

    <script>
    var glbWebFocusUrl = "http://localhost:8080/ibi_apps/WFServlet?IBIF_ex=cardata_as_xml";

    function getXmlData() {
        $.ajax({
            type    : "GET",
            url     : glbWebFocusUrl,
            dataType: "xml",
            success : function(_data) {
                $("#content").empty();
                $(_data).find("navItem").each(function() {
                    var html = "";
                    var $navItem = $(this);
                    html += "<div class='data'>";
                    html +=   "<div class='navItem'>" + $navItem.attr("title") + "</div>";

                    var $subNavItem = $navItem.find('subNavItem');
                    $subNavItem.each(function() {
                        html += "<div class='subNavItem'>" + $(this).attr("url") + " (---" + $(this).attr("title").toLowerCase() + "---)</div>";
                    })

                    html += "</div>";
                    $("#content").append(html);
                });
            }
        });
    }
    </script>
</head>

<body id="body">
  <button onclick=getXmlData()>getXMLData</button>
  <div id="content">
  </div>
</body>
</html>

This message has been edited. Last edited by: <FreSte>,