Xml file as input to FormatasCSV macro fails to return output

abhijit_k
User offline. Last seen 2 years 46 weeks ago. Offline
Joined: 11/12/2008
Points: 80

Hi

I created a sample xml files on monthly attendance of students.  I checked in visual studio .NET, it is a well formed xml file and can retun output in a grid.  I copied this xml file into the folder of webapps\presto\web-inf\classes.   Later I went to Eclipse and created a mashup with macro of 'XMLConstructionFromFile' plugged in it and published the mashup.  I picked up the mashup from mashup explorer and dropped into Wires.  I ran the mashup service to get the erroneous result 'Unable to parse XML - Content is not allowed in prolog'

I share my code both in xml and emml. Please help in resolving the issue.

XML

-------

<?xml version="1.0" encoding="utf-8"?>
<students>
  <student name="ABC">
    <attendance monthname="January" days="22"></attendance>
    <attendance monthname="February" days="20"></attendance>
  </student>
  <student name="DEF">
    <attendance monthname="January" days="20"></attendance>
    <attendance monthname="February" days="17"></attendance>
  </student>
</students>

EMML

---------

<mashup xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.jackbe.com/2008-03-01/EMMLSchema ../src/schemas/EMMLSpec.xsd"
      xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema"
      xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro"
      name = "ReadXMLFile">
 <variables>
    <variable name="xmlConfigData" type="document"/>
  </variables>
  <macro:XMLConstructorFromFile
    filename="students.xml"
    outputvariable="xmlConfigData"/>
 </mashup>

Regards

Abhijit Kulkarni

0
Your rating: None
smitchell
smitchell's picture
User offline. Last seen 20 hours 3 min ago. Offline
Joined: 08/29/2008
Points: 34

Hi Abhijit,

I'm not sure that this is the problem, but your EMML code for the mashup won't produce any output. To get output from the mashup service, you must have an <output> statement in the EMML. And to connect the output of the macro to the output of the mashup, that variable name should be in @outputvariable for the macro. So something like this should allow the mashup service to send data from your XML file: 

<mashup xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="http://www.jackbe.com/2008-03-01/EMMLSchema ../src/schemas/EMMLSpec.xsd"
      xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema"
      xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro"
      name = "ReadXMLFile">
 
    <output name="xmlConfigData" type="document"/>

  <macro:XMLConstructorFromFile
    filename="students.xml"
    outputvariable="xmlConfigData"/>
 </mashup>

Try this, save and republish the mashup service. Then, in Eclipse, trying Service Inspector to test the results of this mashup service. You should be able to see the contents of the XML file as the results. If this works, try the mashup in Wires and let us know if this doesn't solve the problem.

Sara, technical writer/jackbe

 

raj
raj's picture
User offline. Last seen 1 week 5 days ago. Offline
Joined: 09/22/2008
Points: 4

 hi Abhijit,

There are few constraints with the CSV formatter :

1) It currently does not work on XML documents with attributes

2) It works only with XML that are 2-d/flatter structures (not hierarchical), since it has to be converted to flatter CSV format.

In your sample scenario, if the XML structure was modified to be without attributes/flatter i.e.,

<students>

    <attendance>

        <name>ABC</name>

        <monthname>January</monthname>

        <days>22</days>

    </attendance>

    <attendance>

        <name>ABC</name>

      <monthname>February</monthname>

      <days>20</days>

    </attendance>

    <attendance>

        <name>DEF</name>

      <monthname>January</monthname>

      <days>20</days>

    </attendance>

    <attendance>

        <name>DEF</name>

      <monthname>February</monthname>

      <days>17</days>

    </attendance>

</students>

The result would yield

name, monthname, days
ABC,January,22
ABC,February,20
DEF,January,20
DEF,February,17
 
Alternately, you can writing custom EMML Macro/logic to convert your specific complex XML structure to CSV Format. Check out the logic under FormatASCSV Macro in global.emml-macro file for some basis. 
 

raj.  chief masher @ jackbe

abhijit_k
User offline. Last seen 2 years 46 weeks ago. Offline
Joined: 11/12/2008
Points: 80

Hi

I incorporated suggestions both by Sara and Raj.  I modified xml file to remove hirarchy and defined XmlConfigData in output tags.  But to dismay, they both did not work and continued with the same error of  'Unable to parse xml : Content is not allowed in prolog'.

Further help is sought on this problem.

Thanks & Regards

Abhijit Kulkarni

raj
raj's picture
User offline. Last seen 1 week 5 days ago. Offline
Joined: 09/22/2008
Points: 4

Abhijit,

Try this:

1.emml

<mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema" xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro" xsi:schemaLocation="http://www.jackbe.com/2008-03-01/EMMLSchema ../src/schemas/EMMLSpec.xsd" name="ReadXMLFile">

    <output name="csvData" type="string"/>

     <variables>

      <variable name="xmlConfigData" type="document"/>
      </variables>
    <macro:XMLConstructorFromFile filename="students.xml" outputvariable="xmlConfigData"/>

    <macro:FormatAsCSV xmldoc="$xmlConfigData" csvdoc="csvData"/>
</mashup>
 

2. students.xml

<students>    <attendance>
        <name>ABC</name>
        <monthname>January</monthname>
        <days>22</days>
    </attendance>
    <attendance>
        <name>ABC</name>
      <monthname>February</monthname>
      <days>20</days>
    </attendance>
    <attendance>
        <name>DEF</name>
      <monthname>January</monthname>
      <days>20</days>
    </attendance>
    <attendance>
        <name>DEF</name>
      <monthname>February</monthname>
      <days>17</days>
    </attendance>
</students>
 

3. Output I am seeing

name, monthname, days
ABC,January,22
ABC,February,20
DEF,January,20
DEF,February,17

When modifying students.xml, make sure to restart AppServer.

If you are still having issues, attach any stack trace info from logfile.

 

 

 

 

raj.  chief masher @ jackbe

abhijit_k
User offline. Last seen 2 years 46 weeks ago. Offline
Joined: 11/12/2008
Points: 80

Hi Raj

I tried the solution you provided.  It still gives the same error.  This error I get to see exactly identical in words both in eclipse & wires everytime when I run the mashup script.  This is the error I repetatedly get to see in console of eclipse.

Executing Mashup Script C:\Documents and Settings\Administrator\workspace\SelectMashlet\ReadXMLStud1.emml on Server: localhost
Error execution Mashup Script : Error executing script : Wrapped com.jackbe.jbp.sas.nsd.NSDException: Unable to Parse XML :  Content is not allowed in prolog. (#7)

Please advise why I get different output than yours.

Thanks & Regards

Abhijit Kulkarni

 

raj
raj's picture
User offline. Last seen 1 week 5 days ago. Offline
Joined: 09/22/2008
Points: 4

Abhijit,

That is weird, I am was able to run this in version 2.6.1. What version of presto product you are using (you can determine this from Presto home page)

raj.  chief masher @ jackbe

abhijit_k
User offline. Last seen 2 years 46 weeks ago. Offline
Joined: 11/12/2008
Points: 80

Raj

I think you are right.  The version difference might be an issue as I am using 2.6.0 and not 2.6.1.   I will come out with my finding once I use the new version.

Thanks & Regards

Abhijit Kulkarni

 

suniya
User offline. Last seen 34 weeks 3 hours ago. Offline
Joined: 04/19/2011
Points: 0

XMl is a set of rules for encoding documents in machine redable form. It us defines in the XML 1.0 and also in several other related specificatins. Many application programming have been developing interactive intelligence software for several other aid in the defination of XML-based languages.The code which you have used is weird and I was able to run 2.6.1 Vof presto. Visual studio.NET is very good formed xml file and it also can easily return out put in a grid but the codings should be correct.