XMLPort loop question

jordi79
jordi79 Member Posts: 285

Hi,
How do you create xmlport for the following output —>

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<Vendor>
<Name>Vendor Name for vendor 1</Name>
<Name>Vendor Name for vendor 2</Name>
<Name>Vendor Name for vendor 3</Name>
</Vendor>

The closest I could get is:

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<Vendor>
<Name>Vendor Name for vendor 1</Name>
</Vendor>
<Vendor>
<Name>Vendor Name for vendor 2</Name>
</Vendor>
<Vendor>
<Name>Vendor Name for vendor 3</Name>
</Vendor>
<Vendor>
<Name>Vendor Name for vendor 4</Name>
</Vendor>

XMLport code in text (coded in c/al)

OBJECT XMLport 50000 test xml
{
OBJECT-PROPERTIES
{
Date=14-11-25;
Time=[ 2:31:43 PM];
Modified=Yes;
Version List=;
}
PROPERTIES
{
Direction=Export;
}
ELEMENTS
{
{ [{7563C036-F7A4-4DA9-838B-81AD0B2BEE0E}]; ;Vendors ;Element ;Table ;
SourceTable=Table23 }

{ [{5AE1BAC6-168F-4902-A426-01000B497630}];1 ;Name ;Element ;Field ;
DataType=Text;
SourceField=Vendor::Name }

}
EVENTS
{
}
REQUESTPAGE
{
PROPERTIES
{
}
CONTROLS
{
}
}
CODE
{

BEGIN
END.
}
}

Best Answer

  • jordi79
    jordi79 Member Posts: 285
    Answer ✓

    Not going to mention any names here…. but this was a requirement from am international bank. Actually, it was supposed to print description lines. So if the descripton lines exceed a certain length, then it's supposed to print the description on a new element.

    So far, the only way I can think to do this is to hardcode the xmlport to print a fixed no. of elements.

Answers

  • Miklos_Hollender
    Miklos_Hollender Member Posts: 1,629

    First this is not even valid XML, because it lacks a root node. You always need a root node, a text node, in this case you would use the XmlName "Vendor" or "Vendors", which solves half the problem.

    The other half I am not sure about: you need to suppress the TableElement somehow, exporting only the FieldElement. I don't know whether it is possible, maybe empty XMLName?

    You should also talk with whoever defined this requirement, because it is not a common, not a good XML structure IMHO. Good XML structures are not so flat. There is an element defining an entity (table), and under it, the properties of an entity (fields). Just a list of properties of different entities is IMHO not good XML.

  • jordi79
    jordi79 Member Posts: 285
    Answer ✓

    Not going to mention any names here…. but this was a requirement from am international bank. Actually, it was supposed to print description lines. So if the descripton lines exceed a certain length, then it's supposed to print the description on a new element.

    So far, the only way I can think to do this is to hardcode the xmlport to print a fixed no. of elements.

  • ftornero
    ftornero Member Posts: 528

    Hello @jordi79,

    For an XML so simple you could write the file with a report, like this one

    [code]

    OBJECT Report 50001 Export Vendors
    {
    OBJECT-PROPERTIES
    {
    Date=15/11/25;
    Time=18:58:41;
    Modified=Yes;
    Version List=;
    }
    PROPERTIES
    {
    ProcessingOnly=Yes;
    }
    DATASET
    {
    { 1000000000;;DataItem; ;
    DataItemTable=Table23;
    DataItemTableView=SORTING(No.);
    OnPreDataItem=BEGIN
    FileName := TEMPORARYPATH + 'vendors.xml';
    qFile.WRITEMODE(TRUE);
    qFile.TEXTMODE(TRUE);
    qFile.CREATE(FileName);
    qFile.WRITE('<?xml version="1.0" encoding="UTF-8" standalone="no"?>');
    qFile.WRITE('<Vendor>');
    END;

               OnAfterGetRecord=BEGIN
    qFile.WRITE('<Name>' + HTMLEncode(Vendor.Name) +'</Name>');
    END;

    OnPostDataItem=BEGIN
    qFile.WRITE('</Vendor>');
    qFile.CLOSE;
    HYPERLINK(FileName);
    END;
    }

    }
    REQUESTPAGE
    {
    PROPERTIES
    {
    }
    CONTROLS
    {
    }
    }
    LABELS
    {
    }
    CODE
    {
    VAR
    qFile@1000000000 : File;
    FileName@1000000001 : Text;

    PROCEDURE HTMLEncode@1000000000 (Value@1000000000  : Text) : Text;
    VAR
    HttpUtility@1000000001 : DotNet "'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Web.HttpUtility";
    BEGIN
    Value := HttpUtility.HtmlEncode(Value);
    EXIT(Value);
    END;

    BEGIN
    END.

    }
    RDLDATA
    {
    }
    }

    [/code]

    And you get this output

    image.png

    Regards

  • ftornero
    ftornero Member Posts: 528

    Looks like the code is not well formated, here is PDF file

  • ftornero
    ftornero Member Posts: 528

    Maybe the image is more clear.

    image.png