XMLports issue

joeymansonjoeymanson Member Posts: 13
Greetings,

With XMLports, how can I define that an element is to be printed, more than once, depending of the number of relations on other table?

Example:

(...)
<name> [1,1]
<idNumber> [1,1]
<comment> [0,n]
(...)

the element <comments> needs to be filled from another table where the comments are defined (for instance by idNumber table key).

The desirable result of the genarated file is:
(...)
<name>John Smith</name>
<idNumber>9999999</idNumber>
<comment>comment 1</comment>
<comment>comment 2</comment>
<comment>comment 3</comment>
(...)

Anyone can help me please??
Thank you very much!! :mrgreen:

Comments

  • NagiNagi Member Posts: 151
    You can indent elements in an XMLport similar to how you would indent dataitems in a report. You have to set the LinkTable and LinkFields properties of the indentet element.
  • joeymansonjoeymanson Member Posts: 13
    Hi and thx for your reply,

    The problem is that the elements <comment> cant be idented.
    the only thing that i am able to do is something like:
    <comments>
    --<comment>comment 1</comment>
    </comments>
    <comments>
    --<comment>comment 2</comment>
    </comments>
    where tag <comments> is defined as the table of comments with linktable and linkfields related by idNumber of the table of Persons, and comment defined as the field comment of table comments.

    The struture i need to follow is
    <comment>comment 1</comment>
    <comment>comment 2</comment>

    This way, where do i have to define the comment table and link fields without identation?

    I hope you understand what my problem is :D

    Thank you very much
  • NagiNagi Member Posts: 151
    I think this is a limitation with the Xml designer, that you need to indent elements to loop subordinate records. Maybe you could solve your problem using XmlDom, but I haven't tried this myself. However, maybe this post can help you;

    http://www.mibuso.com/forum/viewtopic.p ... xml+indent
  • XypherXypher Member Posts: 297
    Yeah, I would suggest making all that you can through a XMLport then add whatever you cannot in Nav with XMLDom (as Nagi suggested) :wink:


    edit: let us know if you need any help combining the two
  • joeymansonjoeymanson Member Posts: 13
    Nagi wrote:
    I think this is a limitation with the Xml designer, that you need to indent elements to loop subordinate records. Maybe you could solve your problem using XmlDom, but I haven't tried this myself. However, maybe this post can help you;

    http://www.mibuso.com/forum/viewtopic.p ... xml+indent

    This problem is similar to mine but not quite the same.

    the diference is that i dont have a parent node to be defined as table. It seems to me that i would need the same element to be defined as table and field :shock:

    <parentNode>
    --<name>John Smith</name> [field of table of Persons]
    --<idNumber>9999</idNumber> [field of table of Persons]
    --<comment>comment 1<comment> [field of table of Comments]
    --<comment>comment 2<comment> [field of table of Comments]
    --(...)
    </parentNode>

    where comment 1 and comment 2 are comments in a table of comments linked by idNumber.

    Table Persons -> key = idNumber
    Table Comments -> key = idNumber,Comment

    Is this possible with XMLports? If not, is there a way to do this with XMLDom?

    Thx a lot all!! :mrgreen:
  • XypherXypher Member Posts: 297
    Yeah it appears (without seeing the rest of the XML document you're working with) you wont be able to accomplish your goal solely through XMLports.

    Yes you can accomplish this through XMLports + XMLDom. (I suppose you overlooked what I said right above your latest post :\ )
  • joeymansonjoeymanson Member Posts: 13
    Xypher wrote:
    Yeah it appears (without seeing the rest of the XML document you're working with) you wont be able to accomplish your goal solely through XMLports.

    Yes you can accomplish this through XMLports + XMLDom. (I suppose you overlooked what I said right above your latest post :\ )

    Hi there!

    Hi didnt overlooked your last post Xypher, i just wanted to be certain you got my idea :wink:
    So, can you give me any help on how i could to that?
    convert the XML generated by my XMLPort
    <name>John Smith</name>
    <comments>
    --<comment>comment 1</comment>
    <comments>
    <comments>
    --<comment>comment 2</comment>
    </comments>
    (...)
    to
    <name>John Smith</name>
    <comment>comment 1</comment>
    <comment>comment 2</comment>
    (...)

    Thx a lot one more time!
  • XypherXypher Member Posts: 297
    It's real easy to do...
    {
    (X = whichever version you have, hopefully 5+)
    
    xmlDom            Automation 'Microsoft XML, vX.0'.DOMDocument 
    xmlDomRootElement Automation 'Microsoft XML, vX.0'.IXMLDOMElement
    xmlDomNewElement  Automation 'Microsoft XML, vX.0'.IXMLDOMElement
    
    DataRec           Record     'Your Data Table'
    CommentRec        Record     'Your Comment Table'
    BlobRec           Record     TempBlob
    
    BlobOut           OutStream
    BlobIn            InStream
    
    (Of course set BlobRec as Temporary)
    }
    
    BlobRec.Blob.CREATEINSTREAM(BlobIn);
    BlobRec.Blob.CREATEOUTSTREAM(BlobOut);
    
    DataRec.SETFILTER(blahblahblahblah);
    
    XMLPORT.EXPORT(XMLPORT::"Your XMLport", BlobOut, DataRec);
    
    IF ISCLEAR(xmlDom) THEN
      CREATE(xmlDom);
    
    xmlDom.load(BlobIn);
    
    xmlDomRootElement := xmlDom.documentElement;
    
    CommentRec.SETFILTER(DataRecLinkingFilters);
    
    IF CommentRec.FINDFIRST THEN
      REPEAT
        xmlDomNewElement := xmlDom.createNode('element','comment','');
        xmlDomNewElement.Text := CommentRec.Comment;
    
        xmlDomRootElement.appendChild(xmlDomNewElement);
    
        CLEAR(xmlDomNewElement);  //Probably don't need this but threw this in for good measure.
      UNTIL CommentRec.NEXT = 0;
    
    //xmlDom.save('C:\Documents And Settings\joeymanson\Desktop\XMLtest.xml');
    

    Let me know if you have any difficulties with this.

    Cheers!
  • joeymansonjoeymanson Member Posts: 13
    Thx a lot!
    I will try it soon!

    Then, i come here to tell you something... :mrgreen::mrgreen:
  • joeymansonjoeymanson Member Posts: 13
    It looks like the file im trying to generate, is not possible to do with the help of XMLPorts :(

    I think i'll have to generate my whole XML file through code.

    Can you guys direct me to a nice NAV XMLDom Tutorial please?

    Thx! :mrgreen:
Sign In or Register to comment.